• 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

Question about JNDI

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am new to EJB and is confused with where JNDI names are stored.
With the following Xdoclet tags
* @ejb:bean
* name="MyBean"
* jndi-name="ejb/MyBean"
* local-jndi-name="ejb/MyBeanLocal"
* cmp-version="2.x"
* schema="mybean"
* view="both"

When I do a context.lookup("java:comp/env/ejb/MyBeanLocal")
it can find the Ejb Bean. However, if I do
context.lookup("ejb/MyBeanLocal") instead, it would find the object.
I am going thru Enterprise Javabeans 4th Ed and it seems to
suggest that it will work.

Can someone clarify this? I am using Jboss.
I realize that may be related to JNDI_NAME vs COMP_NAME
and I can not find a very detail description of them.
Please help
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

When I do a context.lookup("java:comp/env/ejb/MyBeanLocal")
it can find the Ejb Bean. However, if I do
context.lookup("ejb/MyBeanLocal") instead, it would find the object.


Do you mean using ejb/MyBeanLocal cannot locate the object?

EJB is entitled to a JNDI context, and there is a "place" inside the container to "store" the beans. The InitialContext is the context root, however, inside the container, the subcontext java:comp/env is the root where the beans are navigated.

context.lookup("ejb/MyBeanLocal") works if you had previously locate the context by:


For more details, you could refer to HF EJB pages 602 and 609.

Nick
 
William Wong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for my typo. in fact

context.lookup("java:comp/env/ejb/MyBeanLocal")
DOES NOT work but
context.lookup("ejb/MyBeanLocal")DOES work

with the initialContext.
That is why I am confused.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you show us the full code for that part?

Nick
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code which does not work is in the correct format, which suggests that the EJB server is not compliant with the EJB spec. What server are you using?
 
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
to use this JNDI,you must first declare the ejb reference in the ejb-jar.xml
<ejb-ref> or <ejb-local-ref>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic