Adding EJB references (EJB 1.x)

An EJB reference is a logical name used by a client (or another bean) to locate the home interface of an enterprise bean. You can define references to enterprise beans in EJB modules, J2EE application client modules, and J2EE web modules.

About this task

It is a best practice to use an EJB reference for any enterprise bean that you need to reference. Using an EJB reference allows you to safely write Java™ code to look up 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.

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.

Note:
  • EJB 1.1 enterprise beans and application client modules cannot reference local interfaces of enterprise beans. They must reference the remote interface.
  • In order for a module or a bean to reference the local interface of an enterprise bean, the referenced bean must be included in the same enterprise application (EAR) as the module or bean that is referencing it.
  • If either local or remote references are possible, you should use local references for runtime performance advantages.

For each EJB reference that you define, an ejb-ref element is added to the deployment descriptor.

Procedure

  1. Open the Add Reference wizard from the deployment descriptor editor for your J2EE project.
  2. Select EJB reference and click Next.
  3. Choose one of the following options for specifying the enterprise bean that you want to reference:
    • Enterprise beans in the workspace: Select this option to choose an enterprise bean from the projects currently in your workspace. The tree shows EJB modules in the workspace and lists the available enterprise beans in the EJB modules.
    • Enterprise beans not in the workspace: Select this option to choose an enterprise bean outside of your workspace.
  4. If you selected Enterprise beans in the workspace complete the following steps:
    1. Expand the project tree and select the enterprise bean that you want to reference.
    2. In the Name field, enter a name for the reference.
    3. If you are referencing an EJB 2.1 bean, in the Ref type field specify whether you are referencing the local or remote interface of the enterprise bean.
      Important: If you reference an enterprise bean in another EAR, and that bean's project does not include an EJB client JAR, the workbench automatically creates an EJB client JAR for that referenced EJB project. This improves runtime performance and allows for visibility across different EAR files.
  5. If you selected Enterprise beans not in the workspace, complete the following steps:
    1. In the Name field, enter a name for the reference.
    2. Select Remote from the Ref type drop-down.
    3. In the Type field, specify whether the referenced bean is a session or entity bean.
    4. In the Home field, enter the qualified path to the remote home of the enterprise bean. Click Browse to locate the remote home using the Type Selection window.
    5. In the Remote field, enter the qualified path to the remote interface for the enterprise bean. Click Browse to locate the remote interface using the Type Selection window.
  6. Click Next to review your selections and enter a description for the reference. Click Finish.

Feedback