JPA - Persistence Unit

1 - About

A persistence unit is a set of class (entities,…) that are related or grouped by your application, and which must be collocated in their mapping to a single database.

The persistence unit name is the input parameter of an EntityManager.

A persistence unit includes the following:

3 - Attributes

3.1 - Name

In a Java EE environment, ensure that the persistence unit name is unique within each module.

3.2 - Transaction-type

The transaction type attribute defines which container is used for the entity manager:

  • JTA = J2EE

See JPA - Entity Manager

4 - Example

Example of a persistence unit configuration in the persistence.xml file.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="" 
  <persistence-unit name="myPersistenceUnitName" transaction-type="RESOURCE_LOCAL">
      <property name="" value="Derby"/>            
      <property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.ClientDriver"/>
      <property name="javax.persistence.jdbc.url" value="jdbc:derby://localhost:1527/jpatutorial;create=true"/>
      <property name="javax.persistence.jdbc.user" value="app"/>
      <property name="javax.persistence.jdbc.password" value="app"/>
      <property name="eclipselink.logging.level" value="ALL"/>            


  • the node <persistence-unit> defines the persistence unit where you can find the name and transaction-type attribute of the persistence unit
  • the node <provider> defines the provider
  • the node <class> defines the entities
  • the node <property> defines the provider property

5 - Documentation / Reference

  • See chapter 8.1 of the specification

Data Science
Data Analysis
Data Science
Linear Algebra Mathematics

Powered by ComboStrap