JPA Metamodel and Graphs
The Jakarta Persistence (JPA) Metamodel API provides a type-safe way to introspect the persistent object model at runtime. It allows developers to programmatically examine entities, embeddables, and their attributes to build dynamic queries and validate persistence structures.
The Metamodel
Access the persistence unit metadata through the main entry point interface:
Serves as the central repository for all managed types within a persistence unit (or an ObjectDB database). It provides methods to retrieve entity and attribute information by class or name, similar to the reflection API in Java.
The metamodel represents the domain model through a hierarchy of types and attributes, described in the following subsections:
Describes the hierarchy of persistent types, including entities, mapped superclasses, and embeddables.
Describes the hierarchy of attributes (persistent fields and properties), covering singular, plural (collection), and map attributes.
For detailed examples and further explanation, refer to the JPA Metamodel API section in the ObjectDB manual.
Criteria query integration
Integrate metamodel objects with the Criteria API using the following interface:
Represents objects that can be bound to a Path in a Criteria query, mainly to define FROM variables. It is the common super-interface of both EntityType and Attribute.
Retrieval optimization with Graphs
The API supports the definition of fetch graphs to optimize data loading strategies at runtime:
Describes Entity Graphs and Subgraphs. These structures act as "mini-models" or a focused view of the full metamodel, serving as a template to specify exactly which attributes and relationships should be loaded eagerly.