This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
I am confused on how the look up for a (remote) home object should be done. Should it be initialContext.lookup(java:comp/ejb/CustomerHome); or should it be just be initialContext.lookup("CustomerHome");
"CustomerHome" is a real JNDI name; the name with which you deployed the EJB into the application server. "java:comp/ejb/CustomerHome" is a private JNDI name that you need to map into a real JNDI name using the EJB deployment descriptors.
so then when you are writing a EJB client to access the EJB's, I would think that, since you map java:comp/env/ejb/CustomerHome using the deployment descriptors, all you need to do in the client code is initialContext.lookup("CustomerHome"); Am I right?
Nope (check what he said, Lasse). In your client code you would ONLY refer to initialContext.lookup("java:comp/env/ejb/CustomerHome"). That way regardless of what the real JNDI name is changed to your client code never changes... Kyle
Originally posted by Kyle Brown: In your client code you would ONLY refer to initialContext.lookup("java:comp/env/ejb/CustomerHome").
Kyle, I am confused now. Let me re-ask this question. I came across a multiple choice question which was Which of the following is the best way to find the Home Object. Choose one. 1) Object obj=initialContext.lookup("java:comp/env/ejb/CustomerHome") 2) Object obj=initialContext.lookup("CustomerHome")
I looked through "Mastering EJB-Ed Roman" and all the client code had option 2 there. It said that you give your home object a "nick-name" and then always do a look-up on that nick name. But then I did not find anything wrong with option 1. What do you think? PK
Joined: Aug 10, 2001
Option (1) was all that was available prior to EJB 1.1 and thus all older code samples use it. However, Option (2) is to be GREATLY preferred for all new code. Kyle