This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes JNDI Question... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "JNDI Question..." Watch "JNDI Question..." New topic

JNDI Question...

Dave Hewitson

Joined: Jun 01, 2001
Posts: 27
I'm sucessfully getting session ebj from a servlet with...
Context ctx = new InitialContext();
Object obj = ctx.lookup(java:comp/env/ejb/EmployeeProcessorHome);
...and I can do the same for my entity ejb
Object obj = ctx.lookup(java:comp/env/ejb/EmployeeHome);
But when I try and get hold of the entity ejb from within the session ejb I get the error...
javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:".
I've read that you access an ejb from another ejb in the same way that a client would, so I can't work out what's going wrong here.
Any ideas?
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
You generally look components up using the "java:comp/env" when you define references to them in the deployment descriptors. Have you defined references to your EJBs inside your web application (web.xml) deployment descriptor?
To look up an entity bean from a session bean you have two choices.
(1) Look it up through the global JNDI name (i.e. the name that is defined in the deployment descriptor).
(2) Look it up through a "symbolic reference" where you define a reference to the entity bean inside the session bean deployment descriptor.
Is that of any use?
Dave Hewitson

Joined: Jun 01, 2001
Posts: 27
Hi Simon - thanks for replying.
I definately have the references setup in web.xml - I can use the java:comp/env/ejb/EmployeeHome in the servlet, just not when I try and do the same thing from within the session ejb - It's as though the Context ctx = new InitialContext(); line gives different things in each case.
I'm not sure what you mean by a "symbolic reference" I thought the two options open to me were to use reference (ie java:comp...) or just directly (ie ejb/EmployeeHome).
Do you have any further info on this?
I agree. Here's the link:
subject: JNDI Question...
It's not a secret anymore!