wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes EJB lookup Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB lookup" Watch "EJB lookup" New topic
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: EJB lookup