8.9 Allocating persistence.xml
You allocate persistence.xml in the EJB-JAR, WAR, or EAR. Make sure that you place persistence.xml under META-INF. The path with persistence.xml under META-INF is called the persistence unit root.
The locations in which persistence.xml can be allocated are as follows:
-
META-INF/persistence.xml of EJB-JAR
-
WEB-INF/classes/META-INF/persistence.xml of the WAR
-
META-INF/persistence.xml in the jar file placed under WEB-INF/lib of the WAR
-
META-INF/persistence.xml in the jar file placed in the EAR root directory
-
META-INF/persistence.xml in the jar file placed in the EAR library directory
You can define multiple persistence units in one persistence.xml. You must name the persistence unit. However, you cannot define multiple persistence units with duplicated names in one EJB-JAR, WAR, or EAR.
The class managed with the persistence unit defined in EAR is loaded using the application class loader and can be referenced from all the components in the application.
Furthermore, when the same entity class is referenced from the components in different EJB-JAR and WAR, the referenced class is the same unique class even if the persistence units are different.