Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JNDI Question...

 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
TIA
Dave
 
Simon Brown
sharp shooter, and author
Ranch Hand
Posts: 1913
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Simon
 
Dave Hewitson
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
Dave.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic