Managing the persistence.xml file

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

You can create a stub persistence.xml file in the META-INF directory when you create a JPA project (see "Creating a new JPA project"). You can manage this file either through the XML editor (see ) or through the persistence.xml Editor.


Note:

Depending on your JPA implementation (for example, EclipseLink), the following additional pages may be available in the persistence.xml Editor:
  • 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.

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.

    Property Description Element Defined
    Name Enter the name of the persistence unit. <persistence-unit name = "<Name>">
    Persistence Provider Enter the name of the persistence provider. <provider>
    Description Enter a description for this persistence unit. This is an optional property. <description>
    Managed Classes Add or remove the classes managed through the persistence unit. <class>
      Exclude Unlisted Classes Select to include all annotated entity classes in the root of the persistence unit. <exclude-unlisted-classes>
    XML Mapping Files Add or remove the object/relational mapping XML files define the classes managed through the persistence unit. <mapping-file>
      Exclude Unlisted EclipseLink XML Mapping File Select to include all annotated EclipseLink mapping files.

    Note: This field applies only when using EclipseLink JPA implementation

    <property name="eclipselink.exclude-eclipselink-orm" value="true"/>

  3. 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.

  4. 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.

Related reference

persistence.xml Editor

 

Related task

Synchronizing classes

 

Related concept

The persistence.xml file