Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration/JPA/persistence.xml"

m
m
Line 1: Line 1:
=persistence.xml=
+
= persistence.xml =
A persistence unit configures various details that are required when you acquire an entity manager. You specify a persistence unit by name when you acquire an entity manager factory.
+
A persistence unit configures various details that are required when you acquire an entity manager. You specify a persistence unit by name when you acquire an entity manager factory.  
  
You configure persistence units in the JPA persistence descriptor file: '''persistence.xml'''.
+
You configure persistence units in the JPA persistence descriptor file: '''persistence.xml'''. This file should be in the '''meta-inf/''' directory of your persistence unit jar file, or classpath.
  
In this file, you can specify the vendor extensions that this reference describes by using a '''<properties>''' element.
+
In this file, you can specify the vendor extensions that this reference describes by using a '''&lt;properties&gt;''' element.  
  
 +
<blockquote><source lang="xml">
 +
<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
 +
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
  
{{EclipseLink_JPA
+
  <!-- By default your mappings can be defined in orm.xml file, -->
 +
  <!-- which is discovered automatically.                      -->                                   
 +
  <mapping-file>META-INF/my-mappings.xml</mapping-file>
 +
  ...
 +
  <jar-file>my-additional-jar.jar</jar-file>
 +
  ...
 +
  <!-- Enables auto discovery of persistent classes, -->
 +
  <!-- otherwise they must be listed using <class>  -->
 +
  <exclude-unlisted-classes>false</exclude-unlisted-classes>
 +
 
 +
  <properties>
 +
    ...
 +
  </properties>
 +
</persistence-unit>
 +
</source> </blockquote>
 +
 
 +
 
 +
==How to Specify the Persistence Unit Name==
 +
 
 +
If you are developing your application in a Java EE environment, ensure that the persistence unit name is unique within each module. For example, you can define only one persistence unit with the name "EmployeeService" in an emp_ejb.jar file. The following example shows how to define the name of the persistence unit:
 +
 
 +
<persistence-unit name="EmployeeService">
 +
 
 +
For more information, see Section 6.2.1.1 "name" of the JPA Specification.
 +
 
 +
 
 +
 
 +
<br> {{EclipseLink_JPA
 
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA|JPA]]
 
|previous=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA|JPA]]
 
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/Annotations|Annotations]]
 
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/Annotations|Annotations]]
 
|up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration|Configuration]]}}
 
|up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration|Configuration]]}}

Revision as of 10:51, 15 June 2010

persistence.xml

A persistence unit configures various details that are required when you acquire an entity manager. You specify a persistence unit by name when you acquire an entity manager factory.

You configure persistence units in the JPA persistence descriptor file: persistence.xml. This file should be in the meta-inf/ directory of your persistence unit jar file, or classpath.

In this file, you can specify the vendor extensions that this reference describes by using a <properties> element.

<persistence-unit name="default" transaction-type="RESOURCE_LOCAL">
  <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
 
  <!-- By default your mappings can be defined in orm.xml file, -->
  <!-- which is discovered automatically.                       -->                                     
  <mapping-file>META-INF/my-mappings.xml</mapping-file>
  ...
  <jar-file>my-additional-jar.jar</jar-file>
  ...
  <!-- Enables auto discovery of persistent classes, -->
  <!-- otherwise they must be listed using <class>  -->
  <exclude-unlisted-classes>false</exclude-unlisted-classes>
 
  <properties>
    ...
  </properties>
</persistence-unit>


How to Specify the Persistence Unit Name

If you are developing your application in a Java EE environment, ensure that the persistence unit name is unique within each module. For example, you can define only one persistence unit with the name "EmployeeService" in an emp_ejb.jar file. The following example shows how to define the name of the persistence unit:

<persistence-unit name="EmployeeService">

For more information, see Section 6.2.1.1 "name" of the JPA Specification.



Eclipselink-logo.gif
Version: DRAFT
Other versions...

Back to the top