Jump to: navigation, search

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

Line 6: Line 6:
 
= 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'''. This file should be in the '''meta-inf/''' 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 '''<properties>''' element.
 
 
<source lang="xml">
 
<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 thu 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 in the classpath.
 
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 in the classpath.
Line 83: Line 56:
 
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was '''eclipselink.jdbc.user'''.}}
 
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was '''eclipselink.jdbc.user'''.}}
  
* '''javax.persistence.jdbc.password''' - Standard JPA 2.0 database password for JSE deploym
+
* '''javax.persistence.jdbc.password''' - Standard JPA 2.0 database password for JSE deployments<br />
 +
{{EclipseLink_Note|note=In EclipseLink 1.1, this property was '''eclipselink.jdbc.password'''. }}
 +
 
 +
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|Annotations]]
 +
|up=[[EclipseLink/UserGuide/JPA/Basic JPA Development/Configuration|Configuration]]
 +
|version=2.2.0 DRAFT}}

Revision as of 12:38, 21 March 2011

EclipseLink JPA

link="http://wiki.eclipse.org/EclipseLink"
EclipseLink
Website
Download
Community
Mailing ListForumsIRC
Bugzilla
Open
Help Wanted
Bug Day
Contribute
Browse Source

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 in the 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">
Elug javaspec icon.gif

For more information, see Section 8.2.1 "persistence.xml file" in the JPA Specification.


Additional Properties

Use these persistence.xml or persistence unit properties to further configure your JPA application.

  • javax.persistence.transactionType - Standard JPA PersistenceUnitTransactionType property: JTA or RESOURCE_LOCAL
  • javax.persistence.jtaDataSource - Standard JPA JTA DataSource name.
  • javax.persistence.nonJtaDataSource - Standard JPA non-JTA DataSource name.
  • javax.persistence.jdbc.driver - Standard JPA 2.0 JDBC driver class name for JSE deployments

Elug note icon.png

Note: In EclipseLink 1.1, this property was eclipselink.jdbc.driver.

  • javax.persistence.jdbc.url - Standard JPA 2.0 JDBC URL for JSE deployments

Elug note icon.png

Note: In EclipseLink 1.1, this property was eclipselink.jdbc.url.

  • javax.persistence.jdbc.user - Standard JPA 2.0 database user for JSE deployments

Elug note icon.png

Note: In EclipseLink 1.1, this property was eclipselink.jdbc.user.

  • javax.persistence.jdbc.password - Standard JPA 2.0 database password for JSE deployments

Elug note icon.png

Note: In EclipseLink 1.1, this property was eclipselink.jdbc.password.

For a complete list of persistence unit properties see, PersistenceUnitProperties.

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