Home

 

Preparing the entities for deployment in the server

In later chapters we access the JPA entities from EJB 3.0 session beans. For that we have to configure the server with a data source for the ITSOBANK database, and we have to configure the persistence.xml file to specify the JNDI name of the data source.

The data source of the ITSOBANK database is defined in Configuring the data source in WebSphere Application Server:

For user with DB2, we define data sources for both Derby and DB2. The JNDI names are jdbc/itsobank and jdbc/itsobankdb2.
We use jdbc/itsobank for the JPA entities. By changing the JNDI names in the server, we can run with either database without changing the application code.

To let JPA know what database to use at runtime, we have to add the JNDI name of the data source to the persistence.xml file (Example | 2-15). This is only required in the RAD75JPA project, and not in the RAD75JPATest project.

Example 12-15 Persistence.xml file with data source specification

<persistence ......>
	<persistence-unit name="RAD75JPA">
		<jta-data-source>jdbc/itsobank</jta-data-source>
		<class>
		......

Alternative: For testing purposes, the data source can also be configured in the WebSphere Enhanced EAR of an enterprise application. This technique is described in Creating a data source in the enhanced EAR.

ibm.com/redbooks