Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Note

1. The below XML content illustrate the use of the element.

Code Block
XML
XML
borderStylesolid
 
<persistence-unit name="Account" transaction-type="JTA">
 <description>Entities related to bank accounts</description>
 ...                 [...]
 ...
</persistence-unit>

<provider>

The provider element specifies the name of the persistence provider's javax.persistence.spi.PersistenceProvider class. The provider element must be specified if the application is dependent upon a particular persistence provider being used. The provider class supplies EntityManagers for this persistence unit.

...

  • Object/relational mapping XML file named orm.xml may be specified in the META-INF directory in the root of the
    persistence unit.
  • Object/relational mapping XML file named orm.xml may be specified in the META-INF directory of any jar file
    referenced by the persistence.xml.
  • In addition, other mapping files may be referenced by the mapping-file elements of the persistence-unit
    element, and may be present anywhere on the classpath.

An orm.xml file or other mapping file is loaded as a resource by the persistence provider. If a mapping file is specified, the classes and mapping information specified in the mapping file will be used. If multiple mapping files are specified (possibly including one or more orm.xml files), the resulting mappings are obtained by combining the mappings from all of the files. The result is undefined if multiple mapping files (including any orm.xml file) referenced within a single persistence unit contain overlapping mapping information for any given class. The below XML fragment illustrates the usage.

...

  • The class element is used to list a managed persistence class. A list of all named managed persistence classes must be specified in Java SE environments to insure portability.
    *Portable Java SE applications should not rely on the other mechanisms described here to specify the managed persistence classes of a persistence unit.
  • Persistence providers may also require that the set of entity classes that are to be managed must be fully enumerated in persistence.xml.

The following procedure explains how managed persistence classes are searched.

...

Note
Code Block
XML
XML
borderStylesolid
<persistence-unit name="pu1Inheritence">
 <description>Single Table Inheritence example</description>
 <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
 <class>com.jpa.RoadVehicle</class>
 <class>com.jpa.Car</class>
 <class>com.jpa.Coupe</class>
 <class>com.jpa.Motorcycle</class>
 <class>com.jpa.Roadster</class>
 <properties>
   <property name="openjpa.ConnectionURL" value="jdbc:derby:VehicleDB" />
   <property name="openjpa.ConnectionDriverName" value="org.apache.derby.jdbc.EmbeddedDriver" />
   <property name="ConnectionUserName" value="app" />
   <property name="openjpa.jdbc.SynchronizeMappings" value="false" />
 </properties>
</persistence-unit>

The above properties are specific to OpenJPA provider. The OpenJPA provider reads these properties and creates appropriate EntityManagerFactory. The properties supported by OpenJPA is at this link