Versions Compared

Key

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

...

  • Object/relational mapping XML file named orm.xml may be specified in the * META-INF directory in the root of the
    persistence unit.

...

JPA configuration and geronimo plans

The persistence.xml file can declare more than one persistence-units. A persistence-unit declaration in the persistence.xml can be overridden in geronimo plans (geronimo-web.xml or openejb-jar.xml) as follows.

  • If a persistence-unit is declared in both in persistence.xml as well as in a geronimo plan
    (geronimo-web.xml or openejb-jar.xml), the declaration in the geronimo plan will override the declaration
    in the persistence.xml
  • The below example illustrate the overriding feature in geronimo.
Note
Code Block
XML
XML
borderStylesolid

<?xml version="1.0" encoding="UTF-8"?>

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.0"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence  
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

 <persistence-unit name="AccountUnit" transaction-type="JTA">
  <description>ContainerManagedJPA</description>
  <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
  <jta-data-source>AccountDS</jta-data-source>
  <class>sample.jpa.Account</class>
  <class>sample.jpa.Person</class>
 </persistence-unit>

</persistence>

The AccountUnit can be overridden in openejb-jar.xml as follows.

Code Block
XML
XML
borderStylesolid

<openejb-jar xmlns="http://openejb.apache.org/xml/ns/openejb-jar-2.2" 
 xmlns:naming="http://geronimo.apache.org/xml/ns/naming-1.2" 
 xmlns:sec="http://geronimo.apache.org/xml/ns/security-2.0" 
 xmlns:sys="http://geronimo.apache.org/xml/ns/deployment-1.2">
 
 <sys:environment>

  <sys:moduleId>
   <sys:groupId>ContainerManagedJPA</sys:groupId>
   <sys:artifactId>EJB</sys:artifactId>
   <sys:version>1.0</sys:version>
   <sys:type>car</sys:type>
  </sys:moduleId>

 <dependencies>
  <dependency>
   <groupId>console.dbpool</groupId>
   <artifactId>AccountDS1</artifactId>
  </dependency>
 </dependencies>

 </sys:environment>

 <persistence xmlns="http://java.sun.com/xml/ns/persistence">
  <persistence-unit name="AccountUnit" transaction-type="JTA">
   <description>ContainerManagedJPA</description>
   <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
   <jta-data-source>AccountDS1</jta-data-source>
   <class>sample.jpa.Account</class>
   <class>sample.jpa.Person</class>
  </persistence-unit>
 </persistence>
 
 <enterprise-beans/>

</openejb-jar>

The AccountUnit is overridden in openejb-jar.xml to use the JTA datasource AccountDS1. In the persistence.xml, it was declared to use the JTA datasource AccountDS.

Similarly, the persistence-units can be overridden in geronimo-web.xml right after the <sys:environment> declaration.