Generate your entities classes. These
are Plain Old Java Object (POJO)
entities. Depending upon your development model, you might use some
or all of the JPA tools:
- Top-down mapping
- You start from scratch with the entity definitions and the object-relational
mappings, and then you derive the database schemas from that data.
If you use this approach, you are most likely concerned with creating
the architecture of your object model and then writing your entity
classes. These entity classes would eventually drive the creation
of your database model. If you are using a top-down mapping of the
object model to the relational model, develop the entity classes and
then use OpenJPA functionality to generate the database tables that
are based on the entity classes. The wsmapping tool
would help with this approach.
- Bottom-up mapping
- You start with your data model, which are the database schemas,
and then you work upwards to your entity classes. The wsreversemapping tool
would help with this approach.
- Meet in the middle mapping
- Probably the most common development model. You have a combination
of the data model and the object model partially complete. Depending
on the goals and requirements, you must negotiate the relationships
to resolve any differences. Both the wsmapping tool
and the wsreversemapping tool would help with this
approach.
The JPA solution for the application server provides
several tools that help with developing JPA applications. Combining
these tools with IBM® Rational® Application Developer
provides a solid development environment for either Java EE or Java SE
applications. Rational Application
Developer includes GUI tools to insert annotations, a customizedpersistence.xml file
editor, a database explorer, and other features. Another alternative
is the Eclipse Dali project. More information about Rational Application Developer or the Eclipse
Dali plug-in can be found at their respective websites.
Compile the entity classes. Compile the entities
as you would any Java class,
unless you are using the Criteria API. If you are using the Criteria
API, you must also generate the Criteria API metamodel classes by
including the following option with the
javac command:
-Aopenjpa.metamodel=true
The
following are examples of how you use this option.
For more information
about using Criteria API and AnnotationProcessor6, refer to the Apache
OpenJPA User Guide, Chapter 11: JPA Criteria and Chapter 4: Generation
of Canonical Metamodel classes for AnnotationProcessor6 options and
the information center topic, Criteria API.
Optional: If you are using DB2® and want to use static Structured
Query Language (SQL), run the wsdbgen command.
In order to use the wsdbgen command, IBM Optim PureQuery
Run time must be installed. The wsdbgen command
creates the persistence_unit_name.pdqxml file
under the same META-INF directory where your persistence.xml file
is located. If you have multiple persistence units, the wsdbgen command
must be run for each persistence unit.When multiple pdqxml files
are referenced by an application, use the Merge utility
to combine them into a single pdqxml file. Specify
the combined pdqxml file as pureQueryXml property
of pdqProperties. See the Merge utility documentation in the IBM Integrated Data Management information
center.
Avoid trouble: Applications
that utilize JPA and are configured to run static SQL can experience
various exceptions. These exceptions might occur with the
wsdbgen command,
which you can use to prepare the application, or when the application
is running and calls a JPA method. To resolve this problem, complete
the following:
- Install the program temporary fixes (PTF) for the iSeries® JDBC Driver V5R4. Install PTF numbers
SI32561 and SI32562. You can find the PTFs through the IBM System
i® Support: PTF Cover Letters website.
- If you use DB2
Universal Database for iSeries V6R1
or V5R3, visit the fix web site for the appropriate release.
- Install the required level of IBM Optim PureQuery Run time, which
is Version 1.3.100 or later. For more information, see the IBM Data Studio pureQuery Runtime® website.
Install the latest JCC drivers, which is Version 3.52.95 or later,
with the fix for APAR PK65069. The latest JCC drivers are part of
the IBM DB2 software package.
- For DB2 on a z/OS® server, install PTF UK39204 for the V8
alternate driver or PTF UK39205 for V9, and install the fix for APAR
PK67706.
gotcha
For examples on how to run this command, see the topic, wsdbgen command.