Assembling a JPA application in a Java EE environment
You have developed and configured the applications to work with the Java Persistence API (JPA). Now we need to package the JPA applications for the environment.
Package the application. There are several packaging options for an application that uses JPA in a Java EE environment. Choose the packaging option that best suits the JPA usage and configuration within the modules of the application. These are some of the most common packaging options. For a definitive list of packaging options, see the Java Persistence API specification.
IBM Optimâ„¢ PureQuery Runtime, add the persistence_unit_name.pdqxml file to the JPA application JAR file. The files are located in same META-INF directory where the persistence.xml file is located. These persistence files were created during the development task. See the topic, Developing JPA applications for a Java EE environment for more information.
- For a standalone EJB module or a stand-alone application client module, package the EJB and application client modules in a standard JAR file. Ensure that you package the application with these conditions:
- The JAR file must contain the EJB class files or the Java class files for the application client.
- The META-INF directory of the archive must include the persistence.xml file.
- If the application uses mapping files, orm.xml, or a custom mapping file, the JAR file must also contain those files. If the location of the orm.xml file is not specified in the persistence unit, the default location is the META-INF directory of the JAR file.
- The Criteria Metamodel class files that are generated by the Annotation Processor when you developed the application needs to be included in the JAR file in the same location as the entity class files.
- For a stand-alone web module, package the application in a standard WAR file. Ensure that you package the application with these conditions:
- The Criteria Metamodel class files that are generated by the Annotation Processor while developing the application needs to be included in the WAR file in the same location as the entity class files.
- The WAR file must contain the web application class files. The web application class files must be included in the WEB-INF/classes directory or in a JAR file located in the WEB-INF/lib directory of the WAR file.
- The persistence.xml file must be included in the WEB-INF/classes/META-INF directory or in the META-INF directory of a JAR file included in the WEB-INF/lib directory of the WAR file.
- If the application uses mapping files, orm.xml, or a custom mapping file, the WAR file must also contain those files. Mapping files can reside in the WEB-INF/classes directory or in a JAR file contained within the WEB-INF/lib directory of the WAR file. Use the <mapping-file> element of the persistence.xml file to specify the location of mapping files. For example:
<mapping-file>META-INF/JPAorm.xml</mapping-file>
- For enterprise application containing one or more modules, package the application in a standard Enterprise application archive (EAR) file. An enterprise application can contain one ore more EJB module, web module, or application client module. Ensure that you package the application with these conditions:
- If multiple modules use the same persistence unit, we can create a persistence archive and package the persistence archive within the EAR file.
- Include the entity classes, associated Criteria Metamodel classes, any necessary supporting classes, the persistence.xml file, and additional mapping files in the persistence archive file. Follow the packaging rules for EJB and application client modules for the location of the persistence.xml file and mapping files.
- Each module that uses the persistence archive must have a class path entry in its META-INF/MANIFEST.MF file. Here is an example manifest file:
Manifest-Version: 1.0 Class-Path: MyJPAEntities.jar
- If the modules use separate persistence units and share entity classes, we can package the entity classes in a persistence archive and specify different persistence.xml file and mapping files for each module. If the modules do not share entity classes or a persistence configuration, package each module as a standalone EJB module, a stand-alone application client module, or a standalone web application archive and then package them in the EAR file.
What to do next
For more information about the commands, classes or other OpenJPA information, refer to the Apache OpenJPA User Guide.
Related information:
Apache OpenJPA User Guide: JPA
Apache OpenJPA User Guide: JPA Criteria
Apache OpenJPA User Guide