JPA Metadata Overview

JPA requires the persistence of classes to be defined via Metadata. This Metadata can be provided in the following forms

  • XML : the traditional mechanism, with XML files containing information for each class to be persisted.
  • Annotations : using JDK1.5+ annotations in the classes to be persisted
Metadata priority

JPA defines the priority order for metadata as being

  • JPA XML Metadata
  • Annotations

If a class has annotations and JPA XML Metadata then the XML Metadata will take precedence over the annotations (or rather be merged on top of the annotations).



XML Metadata validation

By default any XML Metadata will be validated for accuracy when loading it. Obviously XML is defined by a DTD or XSD schema and so should follow that. You can turn off such validations by setting the persistence property datanucleus.metadata.validate to false when creating your PMF. Note that this only turns off the XML strictness validation, and not the checks on inconsistency of specification of relations etc.