JPA Annotations
Jakarta Persistence (JPA) uses annotations to define metadata that governs how the persistence engine manages objects and their database mappings. These annotations configure entity behavior, lifecycle events, and relationship structures across various architectural layers.
Class level definitions
Use class-level annotations to define persistent types and configure class-level behavior:
Define classes as entities, embeddables, or mapped superclasses while configuring caching and listener behavior.
Declare static, reusable JPQL queries directly on the entity class.
Optimize data retrieval by defining named entity graphs for eager loading strategies.
Field level configuration
Configure the internal state, identity, and associations of an entity using field-level annotations:
Map individual fields to persistent state, including primary keys, enumerated types, and temporal data.
Define associations between entities, such as one-to-one or many-to-many, and specify cascade and fetch policies.
Automate the generation of primary keys and other field values using various strategies.
Lifecycle and injection
Manage entity lifecycle events and container resource injection with the following annotations:
Designates methods to be triggered by entity lifecycle events (e.g., PrePersist, PostLoad).
Configures the injection of EntityManager and EntityManagerFactory resources in Jakarta EE and Spring environments.
Relational and SQL mapping
The following categories provide metadata specifically for Object-Relational Mapping (ORM) and
native SQL execution; ObjectDB ignores these relational annotations:
Annotations for mapping objects to relational tables, columns, and foreign keys.
Annotations for defining Native SQL queries and result set mappings.