File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

EJB lookup

 
Deepa Malhotra
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 162
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic