• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please explain which is the right way to look up a home  RSS feed

 
J Bhatt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a EJBfactory which has the following method to lookup a Home interface. I would like to know what is the difference between using method 1 and method 2
Here goes the code

 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bhatt,

Neither one of them actually. I would rather try to cache the home interface after the first successful lookup and retrieve it from cache next time, avoiding redundant lookups. By the way looking up the local home interface is never going to be a problem, since it involves an in-process method call. Looking up remote components on the other hand is going to bear extra overhead. In large applications where hundred or maybe thousands of looks up are required, this might induce a serious overhead.
You can review the Service Locator Design pattern:

http://java.sun.com/blueprints/patterns/ServiceLocator.html

Regards.
 
J Bhatt
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You valentin for your reply.
I will change the code to use the service locator pattern.
I am currently using method 2 to lookup the initial context , the application is deployed in QA and in Production environments (both unix) . But I am getting a classcastexception in the production environment , although it is the same ear file that is deployed in both.

when i do a call to get InitialContext using


I hope i am not sounding stupid. Thanks for your reply again.
 
Valentin Tanase
Ranch Hand
Posts: 704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bhatt,

You basically lookup the objects using the syntax "java:comp/env/ejb/LocalHome"[/b] ejb references are specified in your deployment descriptors, which is actually a very good practice. Please search the net for Environment Naming Context (ENC) to understand the reason. The syntax [i]"ejb/RemoteHome" is used when jndi global names are specified and it should be used only with external clients.
In order to understand the reason for getting the exception in production you better check your deployment descriptors and try to understand if you�re defining ejb references for your beans. It still puzzles my why the same ear works in one environment but not the other, since this should have nothing to do with your container�s settings.
Regards.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!