JPA Persistence Unit

A persistence unit defines a set of all user defined persistable classes that are managed by EntityManager instances in an application. This set of entity classes represents the data contained within a single data store. . A Persistence each in turn containing a number of properties and attributes. Persistence units are defined in the persistence.xml file.

persistence.xml:

The persistence.xml file have to be put under the META-INF directory in the classpath. The persistence.xml file can include definitions for one or more Persistence Units. The EntityManagerFactory will need Persistence name to refer the persistence-unit.

persistence.xml example:

<?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"
 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
 
   <persistence-unit name="my-pu">
     <description>Test Persistence Unit</description>
     <provider> org.eclipse.persistence.jpa.PersistenceProvider </provider>
     <mapping-file>META-INF/mappingFile.xml</mapping-file>
     <jar-file>test.jar</jar-file>
     <class>TestEntity1</class>
     <class>TestEntity2</class>
     <properties>
       <property name="propertyName" value="propertyValue"/>
     </properties>
   </persistence-unit>
 
</persistence>