New or updated for this feature pack


Configure JPA to work in your environment

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

New or updated for this feature pack The 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

  1. Configure your data sources through the administrative console. See the topic Configuring a JDBC provider and data source.
    1. If you are using a Java SE environment, see the Configuring data source JDBC providers to use pureQuery in a Java SE environment.
  2. 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>
  3. Configure the properties of the persistence unit in the persistence.xml file to be used in the JPA application.
    1. 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.
    2. 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
    3. 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.
    4. 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>
    5. Add any vendor specific properties to the persistence unit.
  4. Configure persistence provider support in the application server.
    1. Configuring the Java Persistence API (JPA) default persistence provider.
    2. Optional: Using third-party persistence providers.
  5. Specify your database configuration options. If you are using pureQuery, configure your data source to use pureQuery, 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"/>
    1. If you are using pureQuery to access DB2®, see the topic, Configuring JDBC providers to use pureQuery to access DB2
    2. If you are using pureQuery to access Informix®, see the topic, Configuring JDBC providers to use pureQuery 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.



In this information ...


Related reference

IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic    

Terms of Use | Feedback

Last updated: Oct 22, 2010 3:02:28 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=v700osgijpa&product=was-nd-mp&topic=tejb_configjpa
File name: tejb_configjpa.html