JPA Value Generation Annotations

Jakarta Persistence (JPA) supports automatic value generation. This feature is primarily useful for primary key fields, but ObjectDB extends support to regular persistent fields. Several annotations control automatic value generation.

Generation configuration

Configure field-level generation behavior using the following annotation and enumeration:

Specifies that the property or field value should be automatically generated when a new entity object is persisted to the database. It allows defining a specific generator name and strategy.

An enumeration that defines the strategies for primary key generation: AUTO (default), IDENTITY, SEQUENCE, TABLE, or UUID.

Generator definitions

Define specific generator logic at the class level using these annotations:

Defines a named primary key generator that uses a database sequence. It allows you to customize the sequence name, initial value, and allocation size.

Defines a named primary key generator that uses a specific database table to ensure uniqueness. Use this generator when the underlying database doesn't support sequences or identity columns.

For more details about automatic value generation, see the Generated Value section in the ObjectDB Manual.