Interface Graph<J>

All Superinterfaces:
Graph<J>, GraphNode<J>
All Known Subinterfaces:
GraphImplementor<J>, RootGraph<J>, RootGraphImplementor<J>, SubGraph<J>, SubGraphImplementor<J>
All Known Implementing Classes:
GraphImpl, RootGraphImpl, SubGraphImpl

public interface Graph<J> extends GraphNode<J>, Graph<J>
Represents a managed type in an entity graph, acting as a container for:
  • AttributeNode references representing fetched attributes, and
  • treated subgraphs, each represented by a child instance of SubGraph.

A treated (narrowed) subgraph allows fetching to be specified for any attribute of any subtype of the type represented by this graph. The usual way to create a treated subgraph is by calling EntityGraph.addTreatedSubgraph(Class) or addTreatedSubgraph(Class). There are various shortcut operations such as Graph.addTreatedSubgraph(Attribute, Class) which combine creation of a subgraph with creation of a treated subgraph.

Extends the JPA-defined Graph with additional operations.

There are a range of ways to define Graphs:

When a graph is defined programmatically, the new graph is usually instantiated by calling EntityManager.createEntityGraph(Class). However, this requires a reference to and EntityManager, which might not always be convenient. An alternative is provided by EntityGraphs.createGraph(jakarta.persistence.metamodel.EntityType), where the EntityType may be obtained from the static metamodel:

 EntityGraph<Book> graph = EntityGraphs.createGraph(Book_.class_);
 
See Also:
API Note:
Historically, both EntityGraph and this interface declared operations with incorrect generic types, leading to unsound code. This was rectified in JPA 3.2 and Hibernate 7, with possible breakage to older code.