Skip Headers
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g (10.1.3.5.0)

Part Number E13981-01
Go to Documentation Home
Home
Go to Book List
Book List
Go to Table of Contents
Contents
Go to Index
Index
Go to Feedback page
Contact Us

Go to previous page
Previous
Go to next page
Next
View PDF

Configuring an Environment Reference to a Local EJB

You can define an EJB reference to the local interface of a target enterprise bean using one of the following approaches (in increasing order of assembly and deployment flexibility):

Note:

In EJB 3.0, an environment reference to a target enterprise bean is not needed. You can access a target enterprise bean directly using resource injection (see "Accessing an EJB 3.0 Enterprise Bean").

For information on looking up a target enterprise bean, see "Accessing an Enterprise Bean From a Client".

Configuring ejb-local-ref in the Client: No Indirection

Choose this option if the bean interfaces are unique (for example, only one session bean uses the interface Cart.class) or you do not want to use indirection that offers some assembly and deployment flexibility:

  1. Define an <ejb-local-ref> element in the appropriate client deployment descriptor (see "Where do you Configure an EJB Environment Reference?") and configure the following subelements, as Example 19-1 shows:

    • <ejb-ref-name>: the actual name of the target enterprise bean.

    • <ejb-ref-type>: the target bean's type: Session or Entity.

    • <local-home>: the package and class name of the target bean's local home interface.

    • <local>: the package and class name of the target bean's local component interface.

    Example 19-7 Configuring ejb-local-ref-name

    <ejb-local-ref>
     <ejb-ref-name>myBeans/BeanA</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
     <local-home>myBeans.BeanAHome</home>
     <local>myBeans.BeanA</remote>
    </ejb-ref>
    

Configuring ejb-local-ref in the Client: Using ejb-link to Resolve Indirection

Choose this option if the bean interfaces are not unique, or if you want to use indirection that offers some assembly and deployment flexibility:

  1. Define an <ejb-local-ref> element in the appropriate client deployment descriptor (see "Where do you Configure an EJB Environment Reference?") and configure the following subelements, as Example 19-8 shows:

    • <ejb-ref-name>: the logical name of the target enterprise bean.

    • <ejb-ref-type>: the target bean's type: Session or Entity.

    • <local-home>: the package and class name of the target bean's local home interface.

    • <local>: the package and class name of the target bean's local component interface.

    • <ejb-link>: actual name of the target bean

    Example 19-8 Configuring ejb-ref-name with a Logical Name Resolved by ejb-link

    <ejb-local-ref>
     <ejb-ref-name>ejb/nextVal</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
     <local-home>myBeans.BeanAHome</home>
     <local>myBeans.BeanA</remote>
     <ejb-link>myBeans/BeanA</ejb-link>
    </ejb-ref>
    

Configuring ejb-local-ref in the Client: Using orion-ejb-jar.xml ejb-ref-mapping to Resolve Indirection

Choose this option if the following is true:

  • The bean interfaces are not unique.

  • You want to use indirection that offers the most assembly and deployment flexibility.

  1. Define an <ejb-ref> element in the appropriate client deployment descriptor (see "Where do you Configure an EJB Environment Reference?") and configure the following subelements, as Example 19-9 shows:

    • <ejb-ref-name>: the logical name of the target enterprise bean.

    • <ejb-ref-type>: the target bean's type: Session or Entity.

    • <local-home>: the package and class name of the target bean's local home interface.

    • <local>: the package and class name of the target bean's local component interface.

    Example 19-9 Configuring ejb-ref-name With a Logical Name Resolved by ejb-ref-mapping

    <ejb-local-ref>
     <ejb-ref-name>ejb/nextVal</ejb-ref-name>
     <ejb-ref-type>Session</ejb-ref-type>
     <local-home>myBeans.BeanAHome</home>
     <local>myBeans.BeanA</remote>
    </ejb-ref>
    
  2. Within the orion-ejb-jar.xml deployment descriptor, define an <ejb-ref-mapping> element that maps the logical name to the actual name of the target bean, as Example 19-10 shows.

    Example 19-10 Mapping Logical Name to Actual Name With ejb-ref-mapping

    <ejb-ref-mapping name="ejb/nextVal" location="myBeans/BeanA"/>
    

    As Figure 19-5 shows, in the <ejb-ref-mapping> element, configure the name attribute to match the <ejb-ref-name> and configure the location attribute with the actual name of the target bean. In Example 19-10, the logical name ejb/nextVal is mapped to the actual name of the target bean myBeans/BeanA.

    Figure 19-5 Associating ejb-ref-name and ejb-ref-mapping

    Description of Figure 19-5 follows
    Description of "Figure 19-5 Associating ejb-ref-name and ejb-ref-mapping"

    OC4J maps the logical name to the actual JNDI name on the client side. The server side receives the JNDI name and resolves it within its JNDI tree.