|
Oracle® Containers for J2EE Enterprise JavaBeans Developer's Guide
10g Release 3 (10.1.3) B14428-01 |
|
![]() Previous |
![]() Next |
You can access a database through JDBC by creating an environment element for a JDBC DataSource.
|
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 annotations and resource injection (see "Looking Up an EJB 3.0 Resource Manager Connection Factory"). |
For information on looking up a resource manager connection factory, see:
To define a reference to a JDBC DataSource:
Define a <resource-ref> element in the appropriate client deployment descriptor (see "Where Do You Configure an EJB Environment Reference?") and configure its <res-ref-name> element with a logical name for the JDBC data source resource manager connection factory.
It is a best practice to prefixe 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-43), always prefix the logical name with "java:comp/env/".
Figure 19-0 shows a <resource-ref> element in the ejb-jar.xml deployment descriptor with a logical name of jdbc/OrderDB, of type javax.sql.DataSource, and the authenticator of Application.
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.
In the orion-ejb-jar.xml deployment descriptor, define a <resource-ref-mapping> element to map the logical name (defined in ejb-jar.xml) to the JNDI name (defined in data-sources.xml).
Figure 19-2 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).
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-43).