• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

"java:comp/env/" problem

 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have several (local) stateless session EJB's.

From my app I can get a reference to one using something like -

home = (EJBLocalHome) context.lookup("java:comp/env/ejb/ejb1");

but trying to get a reference to another one from a method within ejb1 I
have to use -

home = (EJBLocalHome) context.lookup("ejb/ejb2");

without the "java:comp/env/" bit otherwise I get a NamingException thrown

in my ejb-jar.xml I have -

<ejb-local-ref >
<ejb-ref-name>ejb/ejb2Local</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local-home>uk.gov.ea.prd.interfaces.ejb2LocalHome</local-home>
<local>uk.gov.ea.prd.interfaces.ejb2Local</local>
<ejb-link>ejb2</ejb-link>
</ejb-local-ref>

I am completely stumped as to why this should happen - any ideas?

thanks

harry
 
Ranch Hand
Posts: 346
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I have several (local) stateless session EJB's.

From my app I can get a reference to one using something like -

home = (EJBLocalHome) context.lookup("java:comp/env/ejb/ejb1");

but trying to get a reference to another one from a method within ejb1 I
have to use -

home = (EJBLocalHome) context.lookup("ejb/ejb2");

without the "java:comp/env/" bit otherwise I get a NamingException thrown



This must be happening because all different types of beans are maintained in separate container like Entity beans in different and Session Beans in different and so on. Specifying java:comp/env/ejb means specifying the environment for the component, where it should be looked for, i.e. in ejb. But this environment is already set in case when you try to access a EJB from another EJB, you don't need to specify java:comp/env/ejb again but only the lookup name as mentioned in xml file. As for accessing EJB from Session Bean or from Struts, you have to specify the component environment where to look for the ejb bean, along with its name mentioned in xml file because now you are accessing an entity Bean which lies in another container and not within same container where session Beans are.
reply
    Bookmark Topic Watch Topic
  • New Topic