aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes Home look up Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Home look up" Watch "Home look up" New topic
Author

Home look up

Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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");
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
"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.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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?
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
Yes.
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
Prakash Krishnamurthy
Ranch Hand

Joined: Oct 08, 2002
Posts: 154
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
Kyle Brown
author
Ranch Hand

Joined: Aug 10, 2001
Posts: 3892
    
    5
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Home look up