WAS v8.5 > Administer applications and their environment > Welcome to administering Data access resources > Administer data access applications > Configure a JDBC provider and data source > Use the DB2 Universal JDBC Driver to access DB2 for z/OSConfigure two resource reference files on the same data source
We can configure two resource reference files on the same data source. This allows you to extend the custom properties for the data source to be extended to include two different schema names (currentSQLId on z/OS or currentSchema name in the custom properties) that can be used to exploit the capabilities of the application server.
When an EntityManager is created, the application server obtains a connection to the database. When using a pessimistic transaction, the EntityManager will retain that connection until the EntityManager is closed. When there are two EntityManagers that extend the data source definitions, the openjpa.jdbc.TransactionIsolation property might cause a problem with the transaction. This property can be found in the persistence.xml file in the following entry:
property name="openjpa.jdbc.TransactionIsolation" value="read-committed"
To satisfy this request, Java Persistence API (JPA) will obtain a connection and immediately call setTransactionIsolation(READ_COMMITTED). When we have two EntityManagers share a single physical connection to the database, the first EntityManager creates a connection to the database and involves that connection in a transaction. When the second EntityManager creates a connection, it is not able to change the isolation level.We can avoid this problem by creating two resource reference files in the same data source. We can create the resource references with Rational Application Developer or by editing the XML files. You will need to make changes to the ejb-jar.xml, ibm-ejb-jar-bnd.xml, ibm-ejb-jar-ext.xml, persistence.xml files.
For IBM Optimâ„¢ PureQuery Runtime, if this is an XA data source you must define a new custom property on the data source where property_name = downgradeHoldCursorsUnderXa and boolean value = true. See the following sections for information on how to accomplish this:
- Configure two resource reference files on the same data source using Rational Application Developer.
- Configure two resource reference files on the same data source by editing the XML files.
- Configure two resource reference files on the same data source using Rational Application Developer.
- Edit the ejb-jar.xml file
- Create the deployment descriptor if it doesn't already exist:
- Go to the context menu of the Enterprise Java beans (EJB) project and select Java EE > Generate Deployment Descriptor Stub.
- Edit the deployment descriptor:
- Go to the project's META-INF directory and select the ejb-jar.xml file.
- Add the enterprise bean's element to the deployment descriptor if it doesn't already exist:
- In the left hand pane, select EJB Project node. Click Add.
- In the dialog, select Enterprise Beans. Click OK.
- Add the session bean to the deployment descriptor if it's not already there:
- In the left pane, select Enterprise Beans. Click Add.
- Select Session Bean. Click OK.
- Enter the name of the session bean in the dialog. Click OK.
- In the right-side pane, enter the EJB Class, the business local, and the business remote interfaces.
- Add the resource reference elements to the session bean:
- Select the session bean in the left pane and click Add.
- Select Resource Reference. Click OK.
- In the Add Resource Reference dialog, enter the name, type, authentication and sharing scope fields. Click OK.
- Repeat for the second resource reference.
- Save the editor
- Edit the ibm-ejb-jar-bnd.xml file
- Create the WebSphere EJB bindings descriptor if it doesn't already exist
- Go to the context menu of the EJB project and select Java EE > Generate WebSphere Bindings Deployment Descriptor.
- Edit the bindings descriptor:
- In the project's META-INF directory, select the ibm-ejb-jar-bnd.xml file.
- Add a binding element for the session bean to the bindings descriptor:
- In the left pane, select EJB Jar Bindings node and click Add.
- In the dialog, select Session and click OK.
- In the right pane, enter the name of the session bean.
- Add the bindings for the resource references to the session bean:
- In the left pane, select the session bean and click Add.
- In the dialog, select Resource Reference and click OK.
- In the left pane, select the resource reference.
- In the right pane, enter the name and binding name for the reference
- Repeat for the second resource reference.
- Save the editor
- Edit the ibm-ejb-jar-ext.xml file.
- Create the WebSphere EJB extensions descriptor if it doesn't already exist:
- Go to the context menu of the EJB project and select Java EE > Generate WebSphere Extensions Deployment Descriptor.
- Edit the extensions descriptor:
- In the project's META-INF directory, select the ibm-ejb-jar-ext.xml file.
- Add an extensions element for the session bean to the extensions descriptor:
- In the left pane, select the EJB Jar Extensions node and click Add.
- In the dialog, select Session and click OK.
- In the right pane, enter the name of the session bean.
- Define the isolation level for the resource references:
- In the left pane, select the session bean and click Add.
- In the dialog, select Resource Reference and click OK.
- In the left pane, select the resource reference.
- In the right pane, enter the name and the isolation level.
- Repeat for the second resource reference.
- Save the editor
- Edit the persistence.xml file.
- Add JPA support to the EJB project, which will create the persistence.xml file:
- From the project's context menu, select Properties.
- In the left pane, select the Project Facets node.
- In the right pane, check the box beside Java Persistence.
- Click OK.
- Edit the persistence.xml file:
- In the project's META-INF directory, select the persistence.xml file
- The created persistence.xml file already contains a persistence unit definition. Edit this persistence.xml file
- In the left pane, select the Persistence Unit node. Set the name, JTA data source and exclude the unlisted classes fields.
- Create a new persistence unit definition in the file:
- In the left pane, select the Persistence node and click Add .
- In the dialog, select Persistence Unit and click OK.
- In the left pan, select the Persistence Unit node. Set the name, JTA data source and exclude the unlisted classes fields.
- Add classes to the persistence unit:
- In the left pane, select the persistence unit node and click Add .
- In the dialog, select Class and click OK.
- In the right pane, enter the name of the class.
- Repeat for each class.
- Add properties to the persistence unit
- If there is not already a Properties element in the file, select the persistence unit node in the left pane and click Add.
- In the dialog, select Properties and click OK.
- In the left pane, select the Properties node and click Add.
- In the dialog, select Property and click OK.
- In the right pane, enter the name and value for the property
- Repeat the previous three steps to add the additional properties.
- Save the editor
- Configure two resource reference files on the same data source by editing the XML files.
- Edit the ejb-jar.xml file:
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar id="ejb-jar_ID" metadata-complete="false" version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd"> <enterprise-beans> <session> <ejb-name>NewOrderSessionFacadeBean</ejb-name> <business-local>newordersession.ejb3.NewOrderSessionFacade</business-local> <business-remote>newordersession.ejb3.NewOrderSessionFacadeRemote</business-remote> <ejb-class>newordersession.ejb3.NewOrderSessionFacadeBean</ejb-class> <session-type>Stateless</session-type> <resource-ref> <description></description> <res-ref-name>jdbc/ERWWDataSourceV5</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> <resource-ref> <description></description> <res-ref-name>jdbc/ERWWDataSourceV5_HP</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> <res-sharing-scope>Shareable</res-sharing-scope> </resource-ref> </session> </enterprise-beans> </ejb-jar>- Edit the ibm-ejb-jar-bnd.xml file:
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd" version="1.0"> <session name="NewOrderSessionFacadeBean" simple-binding-name="ejb/session/NewOrderSessionFacadeBean"> <resource-ref name="jdbc/ERWWDataSourceV5" binding-name="jdbc/ERWWDataSourceV5"></resource-ref> <resource-ref name="jdbc/ERWWDataSourceV5_HP" binding-name="jdbc/ERWWDataSourceV5"></resource-ref> </session> </ejb-jar-bnd>- Edit the ibm-ejb-jar-ext.xml file:
<?xml version="1.0" encoding="UTF-8"?> <ejb-jar-ext xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_0.xsd" version="1.0" metadata-complete="true"> <session name="NewOrderSessionFacadeBean"> <resource-ref name="jdbc/ERWWDataSourceV5" isolation-level="TRANSACTION_READ_COMMITTED" /> <resource-ref name="jdbc/ERWWDataSourceV5_HP" isolation-level="TRANSACTION_READ_COMMITTED" /> </session> </ejb-jar-ext>- Edit the persistence.xml file:
<?xml version="1.0" encoding="UTF-8"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0" xsi:schemaLocation= "http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"> <persistence-unit name="NewOrderSessionEJB3"> <jta-data-source>java:comp/env/jdbc/ERWWDataSourceV5</jta-data-source> <class>warehouseejb3.WarehouseJPA</class> <class>districtejb3.DistrictJPA</class> <class>customerejb3.CustomerJPA</class> <class>stockejb3.StockJPA</class> <class>orderejb3.OrderJPA</class> <class>orderlineejb3.OrderlineJPA</class> <class>neworderejb3.NewOrderJPA</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="openjpa.LockManager" value="pessimistic"/> <property name="openjpa.ReadLockLevel" value="read"/> <property name="openjpa.WriteLockLevel" value="write"/> <property name="openjpa.LockTimeout" value="30000"/> <property name="openjpa.FetchBatchSize" value="1" /> <property name="openjpa.jdbc.TransactionIsolation" value="read-committed" /> <property name="openjpa.Log" value="none"/> </properties> </persistence-unit> <persistence-unit name="ItemEJB3"> <jta-data-source>java:comp/env/jdbc/ERWWDataSourceV5_HP</jta-data-source> <class>itemejb3.ItemJPA</class> <exclude-unlisted-classes>true</exclude-unlisted-classes> <properties> <property name="openjpa.LockManager" value="pessimistic"/> <property name="openjpa.ReadLockLevel" value="read"/> <property name="openjpa.WriteLockLevel" value="write"/> <property name="openjpa.LockTimeout" value="30000"/> <property name="openjpa.FetchBatchSize" value="1" /> <property name="openjpa.jdbc.TransactionIsolation" value="read-committed" /> <property name="openjpa.Log" value="none"/> </properties> </persistence-unit> </persistence>
Related
Extend DB2 data source definitions at the application level