!--a11y-->
Enterprise Bean Clients 
Enterprise beans can be accessed by:
· Other enterprise beans
Typically, session beans serve as clients for the entity beans in an EJB application. When the application contains interrelated container-managed entity beans, though, the entity beans also serve as clients for each other.
All enterprise beans are registered in the JNDI name space during application start up. The enterprise bean clients use the enterprise beans’ reference names (defined in the client’s deployment descriptor) to look up them. For example, the following code excerpt can be used to look up the home interface of a bean with reference name ejb/customer:

|
javax.naming.Context ctx = new javax.naming.InitialContext(); CustomerHome customerHome = (CustomerHome) javax.rmi.PortableRemoteObject.narrow(ctx.lookup(“java:comp/env/ejb/customer”), CustomerHome.class); |
To look up the local home interface of a bean with reference name ejb/local_customer, you can use the following source code:

|
javax.naming.Context ctx = new javax.naming.InitialContext(); CustomerLocalHome customerLocalHome = (CustomerLocalHome) ctx.lookup(“java:comp/env/ejb/local_customer”); |
The session and entity enterprise beans provide either a local, or a remote client view, or both. The differences between local and remote access to the enterprise beans are:
|
Local Access |
Remote Access |
|
The clients must reside in the same Java Virtual Machine (JVM) |
The clients may reside in a different Java Virtual Machine (JVM) |
|
The bean must have a local and a local home interface |
The bean must have a remote and a remote home interface |
|
Provides better performance |
May generate a significant overhead if the bean is frequently accessed |
|
Beans that provide local view can be accessed by: · Web components · Other enterprise beans. These beans cannot be accessed by J2EE application clients. |
Beans that provide remote view can be accessed by: · J2EE application clients · Web components · Other enterprise beans |
|
The arguments of the methods of the bean’s interfaces are passed by reference. |
The arguments of the methods of the bean’s interfaces are passed by value. |
|
There are no restrictions for the type of the objects that are passed as parameters of the bean’s methods |
The objects that are passed as parameters of the bean’s methods must be correct RMI-IIOP types |
|
Fine-grained objects (usually entity beans) are typically accessed locally |
Coarse-grained objects (usually session beans) are typically accessed remotely |
|
Entity beans with container-managed persistence, which are in relationships with other container-managed beans, must provide a local view |
-- |

Message-driven beans are not accessed through interfaces. For more information about access to message-driven beans, see Developing Message-Driven Beans.
