Skip Headers
Dali Java Persistence Tools User Guide
Release 3.2
Release 3.2
  PDF
PDF
Go To Table Of Contents
Contents
Go To Index
Index

Previous
Adding virtual attributes
 
Next
Synchronizing classes
 

Managing the persistence.xml file

When you create a project, Eclipse creates the META-INF\persistence.xml file in the project's directory.

Example 3-1 Sample persistence.xml File

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
     <persistence-unit name="QuickStart">
          <class>quickstart.demo.model.Address</class>
          <class>quickstart.demo.model.Item</class>
     </persistence-unit>
</persistence>

You can manage this file either through the XML editor or through the persistence.xml Editor.

Figure 3-26 The persistence.xml Editor

General tab of persistence.xml editor

Note:

Depending on your JPA implementation (for example, EclipseLink), the following pages may be available in the persistence.xml Editor:

  • General – Use this page to define the classes, mapping files, and JAR files for the persistence unit.

  • Connection – Use this page to define the datasource (JTA and non-JTA elements) for the project.

  • Customization – Use this page to define change-tracking and session customizer-related properties.

  • Caching – Use this page to define caching properties.

  • Logging – Use this page to define logging properties.

  • Options – Use this page to define session and target database properties.

  • Schema Generation – Use this page to define DDL-related properties.

  • Properties – Use to add or remove vender-specific properties.

  • Source – Use to view or modify the XML source of the persistence.xml file.

For projects using the EclipseLink JPA implementation, the Connections page also includes JDBC connection pool properties.

If the project uses the Generic platform, then only the General, Connection, Properties and Source pages are available.


To use the persistence.xml Editor:

  1. Open the peristence.xml file. The General page of the editor appears.

  2. Use the General page to define the persistence.xml files <persistent-unit>-related attributes as well as the <provider>, and <class> elements (described in the following table).


    Tip:

    The persistence.xml Editor's Source page enables you to view and edit the raw XML file.


    Figure 3-27 General tab of persistence.xml Editor

    General tab of persistence.xml editor
  3. Complete each field on the General page.

  4. Use the Connection page to define the <jta-data-source> and <non-jta-data-source> elements as follows:

    To configure the JTA (Java Transaction API) source used by the persistence provider:

    1. Select JTA from the Transaction Type list.

    2. Enter the global JNDI name of the data source.

    To configure a non-JTA data source:

    1. Select Resource Local from the Transaction Type list.

    2. Enter the global JNDI name of the data source.


      Note:

      Select Default() to use the data source provided by the container.


    For projects using the Generic platform, you can also define the EclipseLink connection pool driver, connection pool driver, URL, user name and password.

    Figure 3-28 Connection tab of persistence.xml Editor

    Connection tab of persistence.xml Editor
  5. Complete each field on the Connection page.

  6. Use the table in the Properties page to set the vendor-specific <properties> element.

    To add <property> elements:

    1. Click Add.

    2. Enter the <name> and <value> attributes for the <property> element using the table's Name and Value fields.

    To remove a <property> element, select a defined property in the table and then click Remove.


    Note:

    If the project uses the EclipseLink platform, the connection page also includes parameters for JDBC connection pooling.


    Figure 3-29 Customization tab of persistence.xml Editor

    Customization tab of persistence.xml Editor
  7. Complete each field on the Customization page.

Additional pages may be available for the persistence.xml editor, depending on your JPA provider. See "persistence.xml Editor" for more information.

Related reference

Related tasks

Related concepts