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 JDBC Data Source Resource Manager Connection Factory

You can access a database through JDBC by creating an environment element for a JDBC DataSource using deployment XML (see "Using Deployment XML").

Note:

In EJB 3.0, an environment reference to a resource manager connection factory is not needed. You can access a resource manager connection factory directly using resource injection (see "Looking Up an EJB 3.0 Resource Manager Connection Factory").

For information on looking up a resource manager connection factory, see the following:

Using Deployment XML

To define a reference to a JDBC DataSource using deployment XML, do the following:

  1. In the data-sources.xml file, define the desired DataSource and specify its actual JNDI name (see "Configuring Data Sources").

    In this example, assume a DataSource is specified in the data-sources.xml file with the JNDI name of /test/OrderDataSource.

  2. Define a <resource-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-11 shows:

    • <res-ref-name>: the logical name for the JDBC data source.

      It is a best practice to prefix the reference name with jdbc, but it is not required. If you use the initial context to look up this reference in your bean source code (see Example 19-30), always prefix the logical name with java:comp/env/ (for example, java:comp/env/jdbc/OrderDB).

    • <res-type>: the Java type of the resource. For the JDBC DataSource object, this is javax.sq.DataSource.

    • <res-auth>: the source of authentication information, either Application or Container.

    Example 19-11 Configuring <resource-ref> in ejb-jar.xml

    <enterprise-beans>
    ...
        <resource-ref>
            <res-ref-name>jdbc/OrderDB</res-ref-name>
            <res-type>javax.sq.DataSource</res-type>
            <res-auth>Application</res-auth>
        </resource-ref>
    
    </enterprise-beans>
    
  3. In the orion-ejb-jar.xml deployment descriptor, define a <resource-ref-mapping> and configure the following attributes, as Example 19-12 shows:

    • name: the logical name of the data source (defined in ejb-jar.xml).

    • location: the actual name of the data source (defined in data-sources.xml).

    Example 19-12 Mapping Logical to Actual JDBC Data Source Resource Manager Connection Factory Using <resource-ref-mapping>

    <resource-ref-mapping
        name="jdbc/OrderDB"
        location="test/OrderDataSource"
    />
    

    Figure 19-6 shows a <resource-ref-mapping> element with the name attribute set to jdbc/OrderDB (the logical name defined in ejb-jar.xml) and the location attribute set to test/OrderDataSource (the JNDI name defined in data-sources.xml).

    Figure 19-6 Mapping Logical to Actual JDBC Data Source Resource Manager Connection Factory

    This figure shows the JDBC Resource manager mapping.

    Within the bean's implementation, you can look up the JDBC data source resource manager connection factory for this data source using the logical name java:comp/env/jdbc/OrderDB (see Example 19-30).