Interface Graph<J>
- All Known Subinterfaces:
GraphImplementor<J>
,RootGraph<J>
,RootGraphImplementor<J>
,SubGraph<J>
,SubGraphImplementor<J>
- All Known Implementing Classes:
GraphImpl
,RootGraphImpl
,SubGraphImpl
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 Graph
s:
- programmatically, beginning with
Session.createEntityGraph(Class)
, - using the
@NamedEntityGraph
annotation, or - using the mini-language understood by
GraphParser
.
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.
-
Method Summary
Modifier and TypeMethodDescription<Y> AttributeNode<Y>
addAttributeNode
(Attribute<? super J, Y> attribute) Add anAttributeNode
representing the givenAttribute
to 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)SubGraph
associated with the element of the namedPluralAttribute
, or return an existing suchSubGraph
if there is one.<X> SubGraph<X>
addElementSubgraph
(String attributeName, Class<X> type) Create and return a new (mutable)SubGraph
associated with the element of the namedPluralAttribute
, and with the given type, which may be a subtype of the element type, or return an existing suchSubGraph
if there is one.default <X> SubGraph<X>
addKeySubgraph
(Attribute<? super J, X> attribute) Deprecated, for removal: This API element is subject to removal in a future version.default <X> SubGraph<? extends X>
addKeySubgraph
(Attribute<? super J, X> attribute, Class<? extends X> type) Deprecated, for removal: This API element is subject to removal in a future version.<X> SubGraph<X>
addKeySubgraph
(String attributeName) <X> SubGraph<X>
addKeySubgraph
(String attributeName, Class<X> type) <AJ> SubGraph<AJ>
addKeySubGraph
(String attributeName) Deprecated.<AJ> SubGraph<AJ>
addKeySubGraph
(String attributeName, Class<AJ> type) Deprecated.<AJ> SubGraph<AJ>
addKeySubGraph
(MapPersistentAttribute<? super J, ? super AJ, ?> attribute, Class<AJ> type) Deprecated.<K> SubGraph<K>
addMapKeySubgraph
(MapAttribute<? super J, K, ?> attribute) default <AJ> SubGraph<AJ>
addPluralSubgraph
(PluralAttribute<? super J, ?, AJ> attribute) Deprecated, for removal: This API element is subject to removal in a future version.addElementSubgraph(PluralAttribute)
was added in JPA 3.2, and so this method is no longer needed<X> SubGraph<X>
addSubgraph
(Attribute<? super J, X> attribute) default <X> SubGraph<? extends X>
addSubgraph
(Attribute<? super J, X> attribute, Class<? extends X> type) Deprecated, for removal: This API element is subject to removal in a future version.<X> SubGraph<X>
addSubgraph
(String attributeName) <X> SubGraph<X>
addSubgraph
(String attributeName, Class<X> type) <AJ> SubGraph<AJ>
addSubGraph
(String attributeName) Deprecated.<AJ> SubGraph<AJ>
addSubGraph
(String attributeName, Class<AJ> type) Deprecated.<AJ> SubGraph<AJ>
addSubGraph
(PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> type) Deprecated.<AJ> SubGraph<AJ>
addSubGraph
(PersistentAttribute<? super J, AJ> attribute) Deprecated.<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) <AJ> AttributeNode<AJ>
findAttributeNode
(String attributeName) Deprecated.<AJ> AttributeNode<AJ>
findAttributeNode
(PersistentAttribute<? super J, AJ> attribute) Deprecated.<Y> AttributeNode<Y>
getAttributeNode
(Attribute<? super J, Y> attribute) Find an existingAttributeNode
by corresponding attribute reference, within this container.<Y> AttributeNode<Y>
getAttributeNode
(String attributeName) Find an existingAttributeNode
by 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.makeRootGraph
(String name, boolean mutable) Deprecated, for removal: This API element is subject to removal in a future version.This will be removedmakeSubGraph
(boolean mutable) Deprecated, for removal: This API element is subject to removal in a future version.This will be removedMethods inherited from interface jakarta.persistence.Graph
addAttributeNode, addAttributeNodes, addAttributeNodes, getAttributeNodes, hasAttributeNode, hasAttributeNode, removeAttributeNode, removeAttributeNode, removeAttributeNodes
-
Method Details
-
getGraphedType
ManagedDomainType<J> getGraphedType()The managed type of the node.- Returns:
- the
ManagedType
being graphed here.
-
makeRootGraph
@Deprecated(since="7.0", forRemoval=true) RootGraph<J> makeRootGraph(String name, boolean mutable) throws CannotBecomeEntityGraphException Deprecated, for removal: This API element is subject to removal in a future version.This will be removedCreate a named root graph representing this node.- Parameters:
mutable
- controls whether the resulting graph is mutable- Throws:
CannotBecomeEntityGraphException
- If the named attribute is not entity-valued
-
makeSubGraph
Deprecated, for removal: This API element is subject to removal in a future version.This will be removedCreate a new subgraph representing this node. -
makeCopy
Make a copy of this graph node, with the given mutability.If this graph is immutable, and the argument is
false
, simply return this instance. -
getAttributeNodeList
List<? extends AttributeNode<?>> getAttributeNodeList()All nodes belonging to this container.- See Also:
-
getAttributeNode
Find an existingAttributeNode
by name within this container.- Specified by:
getAttributeNode
in interfaceGraph<J>
- Since:
- 7.0
-
getAttributeNode
Find an existingAttributeNode
by corresponding attribute reference, within this container.- Specified by:
getAttributeNode
in interfaceGraph<J>
- Since:
- 7.0
-
findAttributeNode
Deprecated.Find an existingAttributeNode
by name within this container. -
findAttributeNode
@Deprecated(since="7.0") <AJ> AttributeNode<AJ> findAttributeNode(PersistentAttribute<? super J, AJ> attribute) Deprecated.Find an existingAttributeNode
by corresponding attribute reference, within this container. -
addAttributeNode
Add anAttributeNode
representing the givenAttribute
to this node of the graph without creating any associatedSubGraph
.- Specified by:
addAttributeNode
in interfaceGraph<J>
-
addTreatedSubgraph
Create and return a new (mutable)SubGraph
representing the given subtype of the type of this node, or return an existing suchSubGraph
if there is one.- Since:
- 7.0
- See Also:
-
addTreatedSubgraph
Create and return a new (mutable)SubGraph
representing the given subtype of the type of this node, or return an existing suchSubGraph
if there is one.- Since:
- 7.0
-
addSubgraph
Create and return a new (mutable)SubGraph
associated with the namedAttribute
, or return an existing suchSubGraph
if there is one.- Specified by:
addSubgraph
in interfaceGraph<J>
- Parameters:
attributeName
- The name of an attribute of the represented type
-
addSubgraph
Create and return a new (mutable)SubGraph
associated with the namedAttribute
, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraph
if there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Specified by:
addSubgraph
in interfaceGraph<J>
- Parameters:
attributeName
- The name of an attribute of the represented typetype
- A subtype of the attribute type
-
addSubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addSubGraph(String attributeName) throws CannotContainSubGraphException Deprecated.Create and return a new (mutable)SubGraph
associated with the namedAttribute
, or return an existing suchSubGraph
if there is one.- Parameters:
attributeName
- The name of an attribute of the represented type- Throws:
CannotContainSubGraphException
-
addSubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addSubGraph(String attributeName, Class<AJ> type) throws CannotContainSubGraphException Deprecated.Create and return a new (mutable)SubGraph
associated with the namedAttribute
, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraph
if there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Parameters:
attributeName
- The name of an attribute of the represented typetype
- A subtype of the attribute type- Throws:
CannotContainSubGraphException
-
addSubgraph
Create and return a new (mutable)SubGraph
associated with the givenAttribute
of the represented type, or return an existing suchSubGraph
if there is one.- Specified by:
addSubgraph
in 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 CannotContainSubGraphExceptionCreate and return a new (mutable)SubGraph
associated with the givenAttribute
, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraph
if there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Specified by:
addTreatedSubgraph
in interfaceGraph<J>
- Parameters:
attribute
- An attribute of the represented typetype
- A subtype of the attribute type- Throws:
CannotContainSubGraphException
- Since:
- 7.0
- See Also:
-
addTreatedSubgraph
@Incubating <AJ> SubGraph<AJ> addTreatedSubgraph(Attribute<? super J, ? super AJ> attribute, ManagedType<AJ> type) throws CannotContainSubGraphExceptionCreate and return a new (mutable)SubGraph
associated with the givenAttribute
, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraph
if 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
-
addSubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, AJ> attribute) throws CannotContainSubGraphExceptionDeprecated.Create and return a new (mutable)SubGraph
associated with the givenAttribute
of the represented type, or return an existing suchSubGraph
if there is one.- Parameters:
attribute
- An attribute of the represented type- Throws:
CannotContainSubGraphException
- See Also:
-
addSubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addSubGraph(PersistentAttribute<? super J, ? super AJ> attribute, Class<AJ> type) throws CannotContainSubGraphExceptionDeprecated.Create and return a new (mutable)SubGraph
associated with the givenPersistentAttribute
, and with the given type, which may be a subtype of the attribute type, or return an existing suchSubGraph
if 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
- See Also:
-
addElementSubgraph
Create and return a new (mutable)SubGraph
associated with the element of the namedPluralAttribute
, or return an existing suchSubGraph
if there is one.- Specified by:
addElementSubgraph
in interfaceGraph<J>
- Parameters:
attributeName
- The name of a collection-valued attribute of the represented type
-
addElementSubgraph
Create and return a new (mutable)SubGraph
associated with the element of the namedPluralAttribute
, and with the given type, which may be a subtype of the element type, or return an existing suchSubGraph
if there is one.If the given type is a proper subtype of the attribute type, the result is a treated subgraph.
- Specified by:
addElementSubgraph
in 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)SubGraph
associated with the element of the given collection, or return an existing suchSubGraph
if there is one.- Specified by:
addElementSubgraph
in interfaceGraph<J>
- Parameters:
attribute
- A collection-valued attribute of the represented type- Since:
- 7.0
-
addTreatedElementSubgraph
<E> SubGraph<E> addTreatedElementSubgraph(PluralAttribute<? super J, ?, throws CannotContainSubGraphException? super E> attribute, Class<E> type) Create and return a new (mutable)SubGraph
associated 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 suchSubGraph
if there is one.If the given type is a proper subtype of the element type, the result is a treated subgraph.
- Specified by:
addTreatedElementSubgraph
in 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, ?, throws CannotContainSubGraphException? super AJ> attribute, ManagedType<AJ> type) Create and return a new (mutable)SubGraph
associated 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 suchSubGraph
if 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)SubGraph
associated with the key of the named map or return an existing suchSubGraph
if there is one.- Specified by:
addKeySubgraph
in interfaceGraph<J>
- Parameters:
attributeName
- The name of an attribute of the represented type
-
addKeySubgraph
Create and return a new (mutable)SubGraph
associated 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 suchSubGraph
if there is one.- Specified by:
addKeySubgraph
in interfaceGraph<J>
- Parameters:
attributeName
- The name of a map-valued attribute of the represented typetype
- A subtype of the key type
-
addKeySubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addKeySubGraph(String attributeName) throws CannotContainSubGraphException Deprecated.Create and return a new (mutable)SubGraph
associated with the key of the named map or return an existing suchSubGraph
if there is one.- Parameters:
attributeName
- The name of an attribute of the represented type- Throws:
CannotContainSubGraphException
-
addKeySubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addKeySubGraph(String attributeName, Class<AJ> type) throws CannotContainSubGraphException Deprecated.Create and return a new (mutable)SubGraph
associated 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 suchSubGraph
if there is one.If the given type is a proper subtype of the key type, the result is a treated subgraph.
- Parameters:
attributeName
- The name of a map-valued attribute of the represented typetype
- A subtype of the key type- Throws:
CannotContainSubGraphException
-
addMapKeySubgraph
Create and return a new (mutable)SubGraph
associated with the key of the named map, or return an existing suchSubGraph
if there is one.- Specified by:
addMapKeySubgraph
in 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)SubGraph
associated 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 suchSubGraph
if there is one.If the given type is a proper subtype of the key type, the result is a treated subgraph.
- Specified by:
addTreatedMapKeySubgraph
in 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, throws CannotContainSubGraphException?> attribute, ManagedType<AJ> type) Create and return a new (mutable)SubGraph
associated 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 suchSubGraph
if 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
-
addKeySubGraph
@Deprecated(since="7.0") <AJ> SubGraph<AJ> addKeySubGraph(MapPersistentAttribute<? super J, ? super AJ, throws CannotContainSubGraphException?> attribute, Class<AJ> type) Deprecated.Create and return a new (mutable)SubGraph
associated 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 suchSubGraph
if 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
-
addPluralSubgraph
@Deprecated(since="7.0", forRemoval=true) default <AJ> SubGraph<AJ> addPluralSubgraph(PluralAttribute<? super J, ?, AJ> attribute) Deprecated, for removal: This API element is subject to removal in a future version.addElementSubgraph(PluralAttribute)
was added in JPA 3.2, and so this method is no longer neededCreate and return a new (mutable)SubGraph
associated with the element of the given collection, or return an existing suchSubGraph
if there is one.- Since:
- 6.3
- See Also:
-
addSubgraph
@Deprecated(forRemoval=true) default <X> SubGraph<? extends X> addSubgraph(Attribute<? super J, X> attribute, Class<? extends X> type) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
addSubgraph
in interfaceGraph<J>
-
addKeySubgraph
@Deprecated(forRemoval=true) default <X> SubGraph<X> addKeySubgraph(Attribute<? super J, X> attribute) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
addKeySubgraph
in interfaceGraph<J>
-
addKeySubgraph
@Deprecated(forRemoval=true) default <X> SubGraph<? extends X> addKeySubgraph(Attribute<? super J, X> attribute, Class<? extends X> type) Deprecated, for removal: This API element is subject to removal in a future version.- Specified by:
addKeySubgraph
in interfaceGraph<J>
-
addKeySubgraph(String)