File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes Doubt on EJB home Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Doubt on EJB home" Watch "Doubt on EJB home" New topic

Doubt on EJB home

Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 86
Hi Guys,
i have just stared to understand the EJB architecture. and what i gained is that whole idea of Home interface is to create/instantiate the bean(stateful) , EJBObject and give back the stub of EJBObject to the client , so that client can make a call on business methods using that stub.

My question is why we need home interface at all? why cant it be designed with just one interface(EJBObject) , we can register that object of interface with JNDI and client can look up ,get the stub of EJBObject from JNDI and then that stub can be used to create/instantiate the beans with the help of services from container???

SCJP 5.0 94%
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33130

This approach allows the container to do work for you like pooling. It also facilitates creating beans with different constructor params.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
Ravi Bansal
Ranch Hand

Joined: Aug 18, 2008
Posts: 86
Jeanne , thanks for reply.......but i did not understand your point completely....can you elaborate a little more , why cant container still do the job of pooling and any other services(creating beans with different constructors)......what i want to understand if we remove the call to get the home(EJBHome) from JNDI and get the EJBObject from JNDI directly, how this will impact ??
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The purpose of the home object is to create the bean object in the container.

The purpose of the interface object is to allow client objects to call the methods of the bean object (in the container.)

If you remove the call to the home object and never create the bean in the container, then you will not be able to get the interface object from the JNDI namespace because it will not exist.
[ December 25, 2008: Message edited by: James Clark ]
I agree. Here's the link:
subject: Doubt on EJB home
It's not a secret anymore!