| Author |
EJB lookup
|
Deepa Malhotra
Greenhorn
Joined: Oct 31, 2003
Posts: 19
|
|
I notice two ways of getting the home interface. First: MyEJBHome myEJBHome = (MyEJBHome)PortableRemoteObject.narrow(context.lookup("MyEJB"), MyEJBHome.class); Second: MyEJBHome myEJBHome = (MyEJBHome) context.lookup("java:comp/env/ejb/MyEJB"); what is the difference/significance of these two ways.
|
 |
Vinod John
Ranch Hand
Joined: Jun 23, 2003
Posts: 162
|
|
|
If you are trying to cast a remote home interface, according to sun, it is safer to uses PortableRemoteObject.narrow().This become useful when the underlying protocol is IIOP or CORBA. In these case they may not return a remote interface type but might be some signature, which shoud be narrowed to the required type. As long as your app server isn't using RMI-IIOP as a transport protocol, your java casting operater works fine.
|
 |
Deepa Malhotra
Greenhorn
Joined: Oct 31, 2003
Posts: 19
|
|
thanks. With regard to context.lookup("MyEJB") and context.lookup("java:comp/env/ejb/MyEJB"), what is the difference between these two and when they should be used?
|
 |
Vinod John
Ranch Hand
Joined: Jun 23, 2003
Posts: 162
|
|
context.lookup("java:comp/env/ejb/MyEJB") Here you read the ejb's jndi name from the local JNDI namespace. This will will point to MyEJB in the path ejb/ in the local JNDI namespace (think it is also refered as JNDI Enviornment Naming Context). Usage of Local JNDI make the bean much more portable ... you don't have to hard code the JNDI driver, JNDI location and ejb name. The code will be simple like this Set the value for ejb/MyEjb in <ejb-ref> in the config file. If you want to use the 1.1 lookup, you may have to set the driver and location informations.
|
 |
 |
|
|
subject: EJB lookup
|
|
|