Frage

Here Is the code that I have to create an EJB 2.0 How can I convert this so can be used for EJB 3.0

java.lang.Object ejbHomeStub = initCtx.lookup(ejbJNDIName);
EJBHome ejbHome = (EJBHome) 
    javax.rmi.PortableRemoteObject.narrow(ejbHomeStub, EJBHome.class);
EJBMetaData ejbMetaData = ejbHome.getEJBMetaData();
Class ejbHomeClass = ejbMetaData.getHomeInterfaceClass();
//get ejb object of home interface type
ejbHome = (EJBHome) javax.rmi.PortableRemoteObject.narrow(ejbHome, ejbHomeClass);
//create ejb remote object
Method ejbMethodCreate = ejbHomeClass.getDeclaredMethod(EJB_CREATE, null);
ejbRemoteObj = (EJBObject) ejbMethodCreate.invoke(ejbHome, null);
War es hilfreich?

Lösung

If you mean "how do I add EJB 3.0 interfaces to my EJB 2.0 JARs", then you don't need to convert the client or bean since EJB 3.0 is backwards compatible with EJB 2.0. Instead, just update ejb-jar.xml to remove the XSD, add XSD+xmlns, and update the version attribute of <ejb-jar/>.

If you mean "how do I convert this to annotations", then use the @RemoteHome annotation on the bean class, and keep your interfaces the same.

If you mean "how do I convert the EJB to use business interface instead of homes", then you can't do that directly, since you have to know the type of the business interface a priori:

java.lang.Object businessObjectStub = initCtx.lookup(ejbJNDIName);
BusinessObject businessObject = (BusinessObject)
    javax.rmi.PortableRemoteObject.narrow(businessObjectStub, BusinessObject.class);

(Some application servers do not require a narrow for EJB 3.0, but WebSphere Application Server 7.0 does.)

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top