Implement mechanisms for efficient inter-component calls

Bean Interfaces and Implementation

According to the 2.0 specification, the implementation classes for entity beans that use CMP are now abstract classes.

Session beans and entity beans in 2.0 can have two types of interfaces: a remote interface and a local interface.

Typically, however, a bean will be designed to provide only one or the other interface. Similarly, a bean can have a remote home interface and/or a local home interface.

In the 2.0 specification, a bean typically uses its remote interface to expose its methods across the network tier. A bean uses the local interface to expose its methods to other beans that reside within the same container. It is thus possible to directly access a bean through its local interface without the overhead of a remote method call.

Local interfaces provide the foundation for container managed relationships among entity beans and session beans. The bean uses the local interface to maintain its references to other beans. For example, entity beans use local interfaces to maintain relationships to other entity beans. They also allow session and entity beans to be tightly coupled with their clients. Using local interfaces, beans can also expose their state and use pass-by-reference to pass their state between related bean instances.

Adding references to enterprise beans

You can add different types of references to an enterprise bean, including EJB references (local and remote), resource references, security role references, and resource environment references.

An EJB reference is a logical name used by a client (or another bean) to locate the home interface of an enterprise bean. It is a best practice to use an EJB reference for any enterprise bean that you need to reference. Using an EJB reference will allow you to safely write Java code to lookup the home interface of the target enterprise bean without the worry of the binding changing for the target enterprise bean. This is necessary if you need to install the same EJB module on the same server with different bindings.

In addition, for looking up local home interface, you are required to use an EJB local reference.

At deployment, the EJB reference is bound to the enterprise bean's home in the target operational environment. The container makes the application's EJB references available in a JNDI naming context. Resource environment reference elements contain declarations of an enterprise bean's reference to an administered object associated with a resource in the application client's environment. Resource environment references are available only for J2EE 1.3 application clients. For EJB 2.0, the created resource reference has WebSphere Application Server extensions for isolation policy and connection policy.

To add references to an enterprise bean:

  1. In the J2EE Hierarchy view, right-click the desired EJB module and select Open With > Deployment Descriptor Editor from the pop-up menu.

  2. On the References page of the editor select the enterprise bean that you want to add a reference to (the referencing bean) - TravelAgent, and click the Add button. The Add Reference wizard opens.


  3. Select the type of reference that you want to create (EJB local reference), and click Next.

    Add Reference wizard

  4. Select the location of the enterprise bean that you want to reference (the referenced bean).

    Note: Local references can reference enterprise beans in the same EJB project or in the same application. Remote references can also reference enterprise beans in another application.

    When you select an enterprise bean in another EJB project within the same application or another application, the Java JAR dependencies are automatically set up. If you select an enterprise bean in another application and the preference to create EJB client projects is turned on, you will be prompted to create an EJB client project for the EJB project of the selected enterprise bean if one does not already exist. The EJB client project is added as a Java utility JAR to all applications that the source bean projects belongs to. A Java JAR dependency for the source EJB project is also added to the utility JAR file, which is the target EJB client project.

  5. Select the enterprise bean that you are referencing (Cabin), and update the Name field or accept the default (recommended).

    Name - ejb/Cabin

    Add EJB Local Reference wizard

  6. Click Next to review your selections and enter a description for the reference.

    Add EJB Local Reference wizard

  7. Click Finish.

The reference is added to the bean that you selected and is displayed on the References page of the EJB deployment descriptor editor.


<session id="TravelAgent">
	<ejb-local-ref id="EJBLocalRef_1122033021884">

Repeat the same steps and add a reference to (the referencing bean) - TravelAgent for Ship (referenced) bean:


<session id="TravelAgent">
	<ejb-local-ref id="EJBLocalRef_1122300603538">

Professional hosting     Belorussian informational portal         Free SCBCD 1.3 Study Guide     Free SCDJWS 1.4 Study Guide     SCDJWS 1.4 Quiz     Free IBM Certified Associate Developer Study Guide     Free SCJP 5.0 (Tiger) Study Guide     Free Mock Exam Engine     Free SCWCD 1.4 Study Guide