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 "Using the XML Editor to edit the persistence.xml file") or through the persistence.xml Editor.


Note:

In additon to the General, Connection, Properties and Source pages, the persistence.xml Editor pages for projects that use the EclipseLink platform include the following:
  • 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 platform, 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>

  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.

  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

Using the XML Editor to edit the persistence.xml file

 

Related concept

The persistence.xml file