Interface Graph<J>
- All Known Subinterfaces:
GraphImplementor<J>, RootGraph<J>, RootGraphImplementor<J>, SubGraph<J>, SubGraphImplementor<J>
AttributeNodereferences 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:
- programmatically, beginning with
Session.createEntityGraph(Class), - using the
@NamedEntityGraphannotation, or - using the mini-language understood by
GraphParser.
When a graph is defined programmatically, the new graph is usually instantiated by calling
EntityHandler.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
EntityGraphand 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.
-
Method Summary
Modifier and TypeMethodDescription<Y> AttributeNode<Y> addAttributeNode(Attribute<? super J, Y> attribute) Add anAttributeNoderepresenting the givenAttributeto this node of the graph without creating any associatedSubGraph.<E> SubGraph<E> addElementSubgraph(PluralAttribute<? super J, ?, E> attribute) <X> SubGraph<X> addElementSubgraph(String attributeName) Create and return a new (mutable)SubGraphassociated with the element of the namedPluralAttribute, or return an existing suchSubGraphif there is one.<X> SubGraph<X> addElementSubgraph(String attributeName, Class<X> type) Create and return a new (mutable)SubGraphassociated with the element of the namedPluralAttribute, and with the given type, which may be a subtype of the element type, or return an existing suchSubGraphif there is one.<X> SubGraph<X> addKeySubgraph(String attributeName) <X> SubGraph<X> addKeySubgraph(String attributeName, Class<X> type) <K> SubGraph<K> addMapKeySubgraph(MapAttribute<? super J, K, ?> attribute) <X> SubGraph<X> addSubgraph(Attribute<? super J, X> attribute) <X> SubGraph<X> addSubgraph(String attributeName) <X> SubGraph<X> addSubgraph(String attributeName, Class<X> type) <AJ> SubGraph<AJ> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super AJ> attribute, ManagedType<AJ> type) <E> SubGraph<E> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super E> attribute, Class<E> type) <AJ> SubGraph<AJ> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super AJ, ?> attribute, ManagedType<AJ> type) <K> SubGraph<K> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super K, ?> attribute, Class<K> type) <AJ> SubGraph<AJ> addTreatedSubgraph(Attribute<? super J, ? super AJ> attribute, ManagedType<AJ> type) <Y> SubGraph<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> type) addTreatedSubgraph(ManagedType<Y> type) addTreatedSubgraph(Class<Y> type) <Y> AttributeNode<Y> getAttributeNode(Attribute<? super J, Y> attribute) Find an existingAttributeNodeby corresponding attribute reference, within this container.<Y> AttributeNode<Y> getAttributeNode(String attributeName) Find an existingAttributeNodeby name within this container.List<? extends AttributeNode<?>> All nodes belonging to this container.The managed type of the node.makeCopy(boolean mutable) Make a copy of this graph node, with the given mutability.Methods inherited from interface Graph
addAttributeNode, addAttributeNodes, addAttributeNodes, getAttributeNodes, hasAttributeNode, hasAttributeNode, removeAttributeNode, removeAttributeNode, removeAttributeNodes
-
Method Details
-
getGraphedType
The managed type of the node.- Specified by:
getGraphedTypein interfaceGraph<J>- Returns:
- the
ManagedTypebeing graphed here.
-
makeCopy
-
getAttributeNodeList
All nodes belonging to this container.- See Also:
-
getAttributeNode
Find an existingAttributeNodeby name within this container.- Specified by:
getAttributeNodein interfaceGraph<J>- Since:
- 7.0
-
getAttributeNode
Find an existingAttributeNodeby corresponding attribute reference, within this container.- Specified by:
getAttributeNodein interfaceGraph<J>- Since:
- 7.0
-
addAttributeNode
Add anAttributeNoderepresenting the givenAttributeto this node of the graph without creating any associatedSubGraph.- Specified by:
addAttributeNodein interfaceGraph<J>
-
addTreatedSubgraph
-
addTreatedSubgraph
-
addSubgraph
-
addSubgraph
Create and return a new (mutable)SubGraphassociated with the namedAttribute, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Specified by:
addSubgraphin interfaceGraph<J>- Parameters:
attributeName- The name of an attribute of the represented typetype- A subtype of the attribute type
-
addSubgraph
<X> SubGraph<X> addSubgraph(Attribute<? super J, X> attribute) throws CannotContainSubGraphException Create and return a new (mutable)SubGraphassociated with the givenAttributeof the represented type, or return an existing suchSubGraphif there is one.- Specified by:
addSubgraphin interfaceGraph<J>- Parameters:
attribute- An attribute of the represented type- Throws:
CannotContainSubGraphException- See Also:
-
addTreatedSubgraph
<Y> SubGraph<Y> addTreatedSubgraph(Attribute<? super J, ? super Y> attribute, Class<Y> type) throws CannotContainSubGraphException Create and return a new (mutable)SubGraphassociated with the givenAttribute, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Specified by:
addTreatedSubgraphin interfaceGraph<J>- Parameters:
attribute- An attribute of the represented typetype- A subtype of the attribute type- Throws:
CannotContainSubGraphException- Since:
- 7.0
-
addTreatedSubgraph
@Incubating <AJ> SubGraph<AJ> addTreatedSubgraph(Attribute<? super J, ? super AJ> attribute, ManagedType<AJ> type) throws CannotContainSubGraphException Create and return a new (mutable)SubGraphassociated with the givenAttribute, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Parameters:
attribute- An attribute of the represented typetype- A subtype of the attribute type- Throws:
CannotContainSubGraphException- Since:
- 7.0
-
addElementSubgraph
Create and return a new (mutable)SubGraphassociated with the element of the namedPluralAttribute, or return an existing suchSubGraphif there is one.- Specified by:
addElementSubgraphin interfaceGraph<J>- Parameters:
attributeName- The name of a collection-valued attribute of the represented type
-
addElementSubgraph
Create and return a new (mutable)SubGraphassociated with the element of the namedPluralAttribute, and with the given type, which may be a subtype of the element type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Specified by:
addElementSubgraphin interfaceGraph<J>- Parameters:
attributeName- The name of a collection-valued attribute of the represented typetype- A subtype of the element type
-
addElementSubgraph
Create and return a new (mutable)SubGraphassociated with the element of the given collection, or return an existing suchSubGraphif there is one.- Specified by:
addElementSubgraphin interfaceGraph<J>- Parameters:
attribute- A collection-valued attribute of the represented type- Since:
- 7.0
-
addTreatedElementSubgraph
<E> SubGraph<E> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super E> attribute, Class<E> type) throws CannotContainSubGraphException Create and return a new (mutable)SubGraphassociated with the element of the given collection, and with the given type, which may be a subtype of the element type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the element type, the result is a treated subgraph.
- Specified by:
addTreatedElementSubgraphin interfaceGraph<J>- Parameters:
attribute- A collection-valued attribute of the represented typetype- A subtype of the element type- Throws:
CannotContainSubGraphException- Since:
- 7.0
-
addTreatedElementSubgraph
@Incubating <AJ> SubGraph<AJ> addTreatedElementSubgraph(PluralAttribute<? super J, ?, ? super AJ> attribute, ManagedType<AJ> type) throws CannotContainSubGraphException Create and return a new (mutable)SubGraphassociated with the element of the given collection, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the element type, the result is a treated subgraph.
- Parameters:
attribute- A collection-valued attribute of the represented typetype- A subtype of the element type- Throws:
CannotContainSubGraphException- Since:
- 7.0
-
addKeySubgraph
Create and return a new (mutable)SubGraphassociated with the key of the named map or return an existing suchSubGraphif there is one.- Specified by:
addKeySubgraphin interfaceGraph<J>- Parameters:
attributeName- The name of an attribute of the represented type
-
addKeySubgraph
Create and return a new (mutable)SubGraphassociated with the key of the named map, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.- Specified by:
addKeySubgraphin interfaceGraph<J>- Parameters:
attributeName- The name of a map-valued attribute of the represented typetype- A subtype of the key type
-
addMapKeySubgraph
Create and return a new (mutable)SubGraphassociated with the key of the named map, or return an existing suchSubGraphif there is one.- Specified by:
addMapKeySubgraphin interfaceGraph<J>- Parameters:
attribute- A map-valued attribute of the represented type
-
addTreatedMapKeySubgraph
<K> SubGraph<K> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super K, ?> attribute, Class<K> type) Create and return a new (mutable)SubGraphassociated with the key of the named map, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the key type, the result is a treated subgraph.
- Specified by:
addTreatedMapKeySubgraphin interfaceGraph<J>- Parameters:
attribute- A map-valued attribute of the represented typetype- A subtype of the key type
-
addTreatedMapKeySubgraph
@Incubating <AJ> SubGraph<AJ> addTreatedMapKeySubgraph(MapAttribute<? super J, ? super AJ, ?> attribute, ManagedType<AJ> type) throws CannotContainSubGraphException Create and return a new (mutable)SubGraphassociated with the key of the named map, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraphif there is one.If the given type is a proper subtype of the key type, the result is a treated subgraph.
- Parameters:
attribute- A map-valued attribute of the represented typetype- A subtype of the key type- Throws:
CannotContainSubGraphException- Since:
- 7.0
-