Overview
The persistence.xml file describes persistence units. It is the deployment descriptor file for persistence using Java Persistence API (JPA). It is used to declare the following.
- Managed persistence classes.
The managed classes are, for example, those which are annotated using @Entity, @Embeddable or
@MappedSuperclass. - Specify object/relation mapping.
JPA provides several mechanisms to map the java classes to tables in a relational database. - Configuration information for entity managers and entity manager factory classes.
The persistence.xml file is placed in the META-INF directory of the root of the persistence unit. The object/relational mapping information is provided by the following ways.
- Annotations on the managed persistence classes
- One or more XML files contained in the root of the persistence unit
- One or more XML files outside the root of the persistence unit on the classpath and referenced from the
persistence.xml, or a combination of these.
In Java EE, the root of a persistence unit can be one of the following
- EJB-JAR file
- WEB-INF/classes directory of a WAR file
- A jar file in the WEB-INF/lib directory of a WAR file
- A jar file in the root of the EAR
- A jar file in the EAR library directory
- An application client jar file
The location of the managed persistence classes can be as follows.
- Within the root of the persistence unit.
- Can be specified by reference in the persistence.xml by naming the classes, archives, or mapping XML files
that are accessible on the application classpath. - Some combinations of the above methods.
Packaging
The persistence.xml file is placed in the META-INF directory of the root of the persistence unit.
Schema
The schema of the persistence.xml is at this link. Apache geronimo uses OpenJPA as the JPA provider.