A.7. persistence.xml

Files of this type are standard for JPA, and are used for registration of persistent entities and configuration of ORM framework parameters.

A set of persistence.xml files, including the ones defined in base projects, is declared in the cuba.persistenceConfig application property.

When the Middleware block starts, the specified files are combined into a single persistence.xml, stored in the application work folder. File order is important, because each subsequent file in the list can override previously defined ORM parameters. There are several DBMS specific (set in cuba.dbmsType) parameters that cannot be overridden in the persistence.xml. These parameters are:

  • openjpa.jdbc.DBDictionary

  • openjpa.jdbc.MappingDefaults

Additionally, if the cuba.disableOrmXmlGeneration application property is set to false, and the project contains extended entities, the orm.xml file will be created in the application work folder on application start. The path to this file is written to the openjpa.MetaDataFactory parameter, which means that this parameter cannot be defined in the persistence.xml in advance.

Example of a file:

<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
  <persistence-unit name="sales" transaction-type="RESOURCE_LOCAL">
      <class>com.sample.sales.entity.Customer</class>
      <class>com.sample.sales.entity.Order</class>
  </persistence-unit>
</persistence>