8.4.4 Persistence unit
You must define the following information, when the JPA is used from the application:
-
Information about the entity classes in the application
-
Information about the mapping between the entity classes and the database tables
-
Information about the data source for the JPA provider to obtain the database connection
The unit that defines this information is called the persistence unit.
You define the persistence unit in persistence.xml. When the JPA is used in the Java EE environment, persistence.xml is allocated in the determined location in the EJB-JAR, WAR, or EAR files when the user packages the application.
You can include multiple persistence unit definitions in the persistence.xml file. You can also include multiple persistence.xml files in one application. As a result, you can define multiple persistence units in one application. When multiple persistence units are defined in an application, you specify the persistence unit to be used by the application in the unitName attribute of @PersistenceContext. Note that when the persistence unit to be used can be identified uniquely, such as when only one persistence unit is defined in the application, you can omit the unitName attribute.