JPA Fetch Plan Graphs

Jakarta Persistence (JPA) Entity Graphs optimize query performance by specifying which attributes should be loaded eagerly.

Graph definitions

Use the following interfaces to define the hierarchy and scope of your fetch plans:

The root interface for defining a fetch plan. An EntityGraph serves as a template for a query or find operation, allowing you to override the default fetch strategies (Lazy/Eager) at runtime using hints (e.g., jakarta.persistence.fetchgraph).

A nested graph for defining fetch plans of related entities or embeddables. It enables fine-grained control over deep attribute loading within the object hierarchy.

The common super-interface for both entity and subgraphs. It provides the base methods for adding attribute nodes to the graph structure.

Graph elements

Individual components within a graph are represented by the following interface:

Represents a specific entity attribute to be fetched eagerly. AttributeNode instances are added to an EntityGraph or Subgraph to construct the complete fetch plan.