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 (Replacing page with ' '''Warning See "About the Persistence Unit" in the [http://www.eclipse.org/eclipselink/documentation/ EclipseLink Concepts Guide]'''')
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{EclipseLink_UserGuide
 
|info=y
 
|toc=n
 
|eclipselink=y
 
|eclipselinktype=JPA
 
|examples=y
 
|example=*[[EclipseLink/Examples/JPA/Configure|How to Configure]]}}
 
= Configuring Persistence Units Using 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: <tt>persistence.xml</tt>. This file should be in the <tt>meta-inf/</tt> directory of your persistence unit JAR file or in the classpath.
 
  
In this file, you can specify the vendor extensions that this reference describes by using a <tt>&lt;properties&gt;</tt> element.
 
  
<source lang="xml">
+
'''[[Image:Elug_draft_icon.png|Warning]] See "About the Persistence Unit" in the [http://www.eclipse.org/eclipselink/documentation/ EclipseLink Concepts Guide]'''
<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>
+
</source>
+
 
+
 
+
==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 <tt>EmployeeService</tt> in an <tt>emp_ejb.jar</tt> file. The following example shows how to define the name of the persistence unit:
+
 
+
<persistence-unit name="EmployeeService">
+
 
+
{{Template:EclipseLink_Spec
+
|section=Section 8.2.1 "persistence.xml file"
+
}}
+
 
+
 
+
==Additional Properties==
+
Use these '''persistence.xml''' or persistence unit properties to further configure your JPA application.
+
* <tt>javax.persistence.transactionType</tt> - Standard JPA <tt>PersistenceUnitTransactionType</tt> property: <tt>JTA</tt> or <tt>RESOURCE_LOCAL</tt>
+
* <tt>javax.persistence.jtaDataSource</tt> - Standard JPA JTA <tt>DataSource</tt> name.
+
* <tt>javax.persistence.nonJtaDataSource</tt> - Standard JPA non-JTA <tt>DataSource</tt> name.
+
* <tt>javax.persistence.jdbc.driver</tt> - Standard JPA 2.0 JDBC driver class name for JSE deployments <br />
+
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was <tt>eclipselink.jdbc.driver</tt>.}}
+
* <tt>javax.persistence.jdbc.url</tt> - Standard JPA 2.0 JDBC URL for JSE deployments<br />
+
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was <tt>eclipselink.jdbc.url</tt>.}}
+
 
+
* <tt>javax.persistence.jdbc.user</tt> - Standard JPA 2.0 database user for JSE deployments<br />
+
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was <tt>eclipselink.jdbc.user</tt>.}}
+
 
+
* <tt>javax.persistence.jdbc.password</tt> - Standard JPA 2.0 database password for JSE deployments<br />
+
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was <tt>eclipselink.jdbc.password</tt>. }}
+
 
+
For a complete list of persistence unit properties see, [http://www.eclipse.org/eclipselink/api/latest/org/eclipse/persistence/config/PersistenceUnitProperties.html PersistenceUnitProperties].
+
 
+
{{EclipseLink_JPA
+
 
+
|previous=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration|Configuration]]
+
|next=[[EclipseLink/UserGuide/JPA/Basic_JPA_Development/Configuration/JPA/Annotations|Adding Metadata Using Annotations ]]
+
|up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration|Configuration]]
+
|version=2.2.0 DRAFT}}
+

Latest revision as of 11:47, 25 January 2013


Warning See "About the Persistence Unit" in the EclipseLink Concepts Guide

Back to the top