JPA ORM Mapping Annotations

Jakarta Persistence (JPA) provides a comprehensive set of annotations and enums for mapping object models to relational database schemas. These metadata elements define how entities, attributes, and relationships translate to tables, columns, and foreign keys.

While ObjectDB ignores these ORM-specific settings, they remain essential for maintaining compatibility with relational providers.

Table and schema definitions

Use the following annotations to map entities to database tables and define schema-level constraints:

Specifies the primary table for an entity.

Specifies a secondary table for an entity, allowing data for a single entity to be split across multiple database tables.

A container annotation for defining multiple @SecondaryTable entries.

Specifies a unique constraint to be included in the generated DDL for a table.

Column mapping

Map fields to specific database columns using these annotations:

Specifies the mapped column for a persistent property or field.

Specifies that a persistent property or field should be persisted as a large object (BLOB or CLOB).

Specifies a column that is used to maintain the persistent order of a list.

Inheritance mapping

Define how inheritance hierarchies map to relational tables:

Defines the inheritance strategy to be used for an entity class hierarchy.

An enumeration defining the strategies: SINGLE_TABLE, JOINED, or TABLE_PER_CLASS.

Specifies the discriminator column used to distinguish between entity types in the SINGLE_TABLE and JOINED strategies.

Specifies the value that indicates a row belongs to a specific entity type within the hierarchy.

An enumeration defining the data type of the discriminator column (STRING, CHAR, INTEGER).

Relationship linking (joins)

Define foreign keys and join tables for entity relationships:

Specifies a column for joining an entity association or element collection.

A container annotation for defining multiple @JoinColumn entries for composite keys.

Specifies a link table for a many-to-many or unidirectional one-to-many relationship.

Specifies a primary key column that is used as a foreign key to join to another table (often used in JOINED inheritance).

A container annotation for defining multiple @PrimaryKeyJoinColumn entries.

Designates a relationship attribute that provides the mapping for an EmbeddedId primary key or a simple parent key.

Collection and map specifics

Configure mappings for collections and map key columns:

Specifies the table that is used for the mapping of collections of basic or embeddable types.

Specifies the type of the map key for associations of type java.util.Map when the type cannot be determined via generics.

Specifies the mapping for the key column of a map with basic keys.

Specifies a mapping to an entity that is a map key.

A container annotation for defining multiple @MapKeyJoinColumn entries.

Overrides

Override mappings inherited from mapped superclasses or embeddables:

Used to override the mapping of a Basic (field) property or id property.

A container annotation for defining multiple @AttributeOverride entries.

Used to override a relationship mapping (e.g., a @JoinColumn) inherited from a mapped superclass or within an embeddable.

A container annotation for defining multiple @AssociationOverride entries.