You have developed your applications to work with Java Persistence API (JPA) and now
you need to configure your JPA applications to work in your environment.
Before you begin
newfeatThe Feature
Pack for OSGi Applications and JPA 2.0 introduces support for Apache
OpenJPA 2.0.
About this task
You need to specify options for your database as a part of
configuring JPA applications. The application server manages access
to data sources. You can configure the data sources, connection pooling,
and Java Transaction API (JTA)
service in the administrative console. If you have a specific data
source for your application, configure the data source before you
install your JPA application.
Procedure
- Configure your data sources through the administrative
console. See the topic Configuring
a JDBC provider and data source.
- If you are using a Java SE environment, see the Configuring data source JDBC providers to use IBM Optim pureQuery Runtime in a Java SE environment.
- Specify the Java Naming
and Directory Interface (JNDI) names for the <jta-data-source>
and <non-jta-data-source> elements. If you use the component
name space method for data source retrieval, ensure that your application
defines these resource references so that you can use these JNDI names
to access the data source. This configuration provides more flexibility
if you need to alter the configuration for the data source. For more
information on using the JNDI interface, refer to the topic, Developing
applications that use JNDI. For example, the persistence.xml file
would have a entry like the following:
<jta-data-source>java:comp/env/jdbc/FooBarDataSourceJNDI</jta-data-source>
- Configure the properties of the persistence unit in the persistence.xml file
to be used in the JPA application.
- Specify your data source. Use the openjpa.Connection
property to obtain a connection to the database. When you run a JPA
application in a Java SE environment,
a JTA data source is treated as a data source that is not JTA compliant.
- Select com.ibm.websphere.persistence.PersistenceProviderImpl
as the persistence provider.
Avoid trouble: Include
the persistence provider in the classpath if you run the JPA application
as a standalone application.
gotcha
- Specify the transaction type to RESOURCE_LOCAL.
For example, the following entry should be in the persistence.xml file:
<persistence-unit name="persistence_unit" transaction-type="RESOURCE_LOCAL">
For more information, see the topic, Associating persistence
providers and data sources.
- Include the location of the object relationship mapping
file, orm.xml, and any additional mapping files. For
example, the following entry should be in the persistence.xml file:
<mapping-file>META-INF/JPAorm.xml</mapping-file>
- Add any vendor specific properties to the persistence
unit.
- Configure persistence provider
support in the application server.
- Configuring the Java Persistence API (JPA) default persistence provider.
- Optional: Using third-party persistence providers.
- Specify your database configuration options. If
you are using IBM Optim pureQuery Runtime, configure your data source
to use IBM Optim pureQuery Runtime, ensure the pdq.jar and pdqmgmt.jar files
are included on the JDBC provider classpath. The database
type and method of connection is indicated in the persistence.xml file.
<property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="openjpa.ConnectionURL" value="jdbc:derby:target/database/jpa-test-database;create=true"/>
- If you are using IBM Optim pureQuery Runtime to access DB2®, see the topic, Configuring JDBC providers to use IBM Optim pureQuery Runtime to access DB2
- If you are using IBM Optim pureQuery Runtime to access Informix®, see the topic, Configuring JDBC providers to use IBM Optim pureQuery Runtime to access Informix
What to do next
For more information about the commands, classes or other
OpenJPA information, refer to the Apache OpenJPA User's Guide.