JPA - persistence.xml

> JPA - Java Persistence API (JPA)

1 - About

The JPA specification requires the use of a persistence.xml file for deployment.

The persistence configuration file must be named “META-INF/persistence.xml” in the persistence archive.

This file defines one or more persistence unit where:

The Xsd for the persistence configuration file can be found:


3 - Schema

Persistence configuration files must indicate

  • the persistence schema by using the persistence namespace:

  • and indicate the version of the schema by using the version element as shown below:
<persistence xmlns="" 

4 - Node

4.1 - Provider

The provider node define the entity managers class. The provider element is optional but should be specified if the application is dependent upon a particular persistence provider being used. The class must be present in the classpath.

For EclipseLink:


For Hibernate:


For Toplink:


4.2 - exclude-unlisted-classes


All the class that are unlisted will/or not be automatically discovered with reflection. Ie if the @Entity annotations is present, the class is an entity.

5 - Example

5.1 - SE

Eclipselink configuration for a derby database with Logging level as properties

<?xml version="2.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="" 
  <persistence-unit name="TroubleTicketSystemServer" 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"/>            

Add the derby jars to the application classpath

5.2 - EE

<persistence version="2.0" 
    <persistence-unit name="example" transaction-type="JTA">
        <!-- optional --><class></class>
            <!-- optional --><property name="" 
            <property name="" value="WebLogic_10"/>
            <property name="eclipselink.logging.level" value="FINEST"/>

Add derby jars to the application server classpath (Example: for WebLogic place in the modules directory)

6 - Support

6.1 - No Persistence provider for EntityManager

Exception in thread "main" javax.persistence.PersistenceException: No Persistence provider for EntityManager named myProviderUnit:  
The following providers:
Returned null to createEntityManagerFactory.
	at javax.persistence.Persistence.createEntityManagerFactory(
	at test.Main.main(

No persistence provider node with the name myProviderUnit can be found.


7 - Documentation / Reference