• Post Reply Bookmark Topic Watch Topic
  • New Topic

Purpose of the Home Class

 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Im new to J2EE and EJBs and I have a quick question regarding the home interface. On reading some introductory material it explains that a cleint cannot instantiate an EJB objet directly because EJB objects could exist on a different machine than the one the cleint is on. To acquire a reference to an EJB object, your cleint code asks for an EJB OBject from an EJB object factory. This factory is the home object. The cleint finds the home object using the JNDI.
My question is this: If the client has to find the home object using JNDI why could it not use JNDI to find the EJB object directly, thereby removing a step in the creation process...........??
Thanks,
John
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Remember the old CS adage that every problem can be solved by one more layer of indirection? Well, the point here is that there should be more than ONE EJB object, and that the creation should be independent of the location.
The Home is a Factory. That's it, plain and simple. It's responsible for lifecycle management (create, find, delete) of the EJB's. The distribution part is (almost) a red herring.
This is what you want. You don't want to do a JNDI lookup of the bean itself, because then you could only ever have one of them! The alternative (looking up the individual beans in JNDI would be horrendous, because then you'd need to have some unique identifier for each bean --- and that would be true of session as well as entity beans -- too scary to even think about).
Hope this helps.
Kyle
 
John Ryan
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kyle Brown:
Remember the old CS adage that every problem can be solved by one more layer of indirection? Well, the point here is that there should be more than ONE EJB object, and that the creation should be independent of the location.
The Home is a Factory. That's it, plain and simple. It's responsible for lifecycle management (create, find, delete) of the EJB's. The distribution part is (almost) a red herring.
This is what you want. You don't want to do a JNDI lookup of the bean itself, because then you could only ever have one of them! The alternative (looking up the individual beans in JNDI would be horrendous, because then you'd need to have some unique identifier for each bean --- and that would be true of session as well as entity beans -- too scary to even think about).
Hope this helps.
Kyle

Cheers Kyle. I hadnt treally thought about having multiple EJB Objects in different locations..........
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!