This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about JNDI

 
William Wong
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Can you show us the full code for that part?

Nick
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • 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?
 
chao cai
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • 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>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic