3.7.3.3. Persistent Field Values

JPA defines Basic, Lob, Embedded, ManyToOne, and OneToOne persistence strategies for direct field values. OpenJPA supports all of these standard strategies, but adds one of its own: Persistent. The org.apache.openjpa.persistence.Persistent metadata annotation can represent any direct field value, including custom types. It has the following properties:

  • FetchType fetch: Whether to load the field eagerly or lazily. Corresponds exactly to the same-named property of standard JPA annotations such as Basic. Defaults to FetchType.EAGER.

  • CascadeType[] cascade: Array of enum values defining cascade behavior for this field. Corresponds exactly to the same-named property of standard JPA annotations such as ManyToOne. Defaults to empty array.

  • String mappedBy: Names the field in the related entity that maps this bidirectional relation. Corresponds to the same-named property of standard JPA annotations such as OneToOne.

  • boolean optional: Whether the value can be null. Corresponds to the same-named property of standard JPA annotations such as ManyToOne, but can apply to non-entity object values as well. Defaults to true.

  • boolean embedded: Set this property to true if the field value is stored as an embedded object.

Though you can use the Persistent annotation in place of most of the standard direct field annotations mentioned above, we recommend primarily using it for non-standard and custom types for which no standard JPA annotation exists. For example, Multi-Column Mappings demonstrates the use of the Persistent annotation to denote a persistent java.awt.Point field.