Top
Interstage Studio User's Guide
FUJITSU Software

4.3.2 Developing Persistence Units

To develop a persistence unit, define persistence.xml, multiple persistence classes (Entity classes and so on), and O/R mapping files. Code the data source used by the persistence unit and explicitly declare persistence classes and O/R mapping files in persistence.xml.
An O/R mapping file is used to code information for persistence classes that do not use annotation, or to overwrite information that was coded in Java source using annotations.

Point

The orm.xml file created during project creation is an O/R mapping file that does not need to be explicitly declared in persistence.xml.
A persistence class declaration is also not usually required in persistence.xml if annotation is used for development, unless the class is stored in a different JAR file, for example.

Due to the above specifications, persistence unit development consists of using annotation to create the persistence class, and editing persistence.xml and O/R mapping files.
For details, refer to "4.3.3 Creating Entity Classes" for the method for using annotation to create a persistence class.

persistence.xml Editing

To edit persistence.xml, use a Persistence XML editor.
The Persistence XML editor has [General], [Connection], [Properties] and [Source] tabs. From the [Source] tab, direct editing of XML files is possible and Contents Assist can be used to add tags.
In the [General], [Connection] and [Properties] tabs, XML content can be edited using GUI.

For example, code persistence.xml as shown below in order to declare the data source used for the persistence unit.

persistence.xml Usage Example

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
    <persistence-unit name="JPASample">
        <jta-data-source>jdbc/Oracle</jta-data-source>
    </persistence-unit>
</persistence>

O/R mapping File Editing

The XML editor is also used to edit O/R mapping files.

In addition, while the XML editor is open, if EntityMappings is selected in the [JPA Structure] view, the [JPA Details] view can be used to enter settings for a number of elements. For details, refer to below for settings details:

Point

Elements under a persistence unit are suitable for persistence classes coded using annotation. Other items are suited to persistence classes coded using an O/R mapping file (orm.xml).

Validating as a JPA Application

Use the JPA application validator to validate the persistence unit.
For details, refer to "6.2.5.2 Validation" for details of validation.