• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

EJB lookup

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic