Package org.hibernate.graph
Class EntityGraphs
java.lang.Object
org.hibernate.graph.EntityGraphs
A collection of
EntityGraph
utilities.- API Note:
- These operations are things which are arguably missing from JPA.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<S> Subgraph<S>
addTreatedSubgraph
(Graph<? super S> graph, Class<S> subtype) Allows a treated subgraph to ve created for aSubgraph
, since the JPA-standard operationEntityGraph.addTreatedSubgraph(Class)
is declared byEntityGraph
.static boolean
areEqual
(AttributeNode<?> a, AttributeNode<?> b) Compares two entity graph attribute node and returnstrue
if they are equal, ignoring subgraph attribute order.static <T> boolean
areEqual
(EntityGraph<T> a, EntityGraph<T> b) Compares two entity graphs and returnstrue
if they are equal, ignoring attribute order.static boolean
Compares two entity subgraphs and returnstrue
if they are equal, ignoring attribute order.static boolean
Compares two entity subgraph maps and returnstrue
if they are equal, ignoring order.static <T> EntityGraph<T>
createGraph
(EntityType<T> rootType) Create a new entity graph rooted at the given entity, without needing a reference to the session or session factory.static EntityGraph<Map<String,
?>> createGraphForDynamicEntity
(EntityType<?> rootType) Create a new entity graph rooted at the given dynamic entity, without needing a reference to the session or session factory.static List
executeList
(Query query, EntityGraph<?> graph) Deprecated.Since it is not type safe and returns a raw typestatic List
executeList
(Query query, EntityGraph<?> graph, String semanticJpaHintName) Deprecated.Since it is not type safe, returns a raw type, and accepts a stringstatic List
executeList
(Query query, EntityGraph<?> graph, GraphSemantic semantic) Deprecated.Since it is not type safe and returns a raw typestatic <R> List<R>
executeList
(TypedQuery<R> query, EntityGraph<R> graph) Deprecated.UsesetFetchGraph(TypedQuery, EntityGraph)
insteadstatic <R> List<R>
executeList
(TypedQuery<R> query, EntityGraph<R> graph, String semanticJpaHintName) Deprecated.Since it accepts a string instead ofGraphSemantic
static <R> List<R>
executeList
(TypedQuery<R> query, EntityGraph<R> graph, GraphSemantic semantic) Deprecated.UsesetGraph(TypedQuery, EntityGraph, GraphSemantic)
insteadstatic <T> EntityGraph<T>
merge
(EntityManager entityManager, Class<T> root, Graph<T>... graphs) Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.static <T> EntityGraph<T>
merge
(EntityManager entityManager, Class<T> root, List<? extends Graph<T>> graphs) Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.static <T> EntityGraph<T>
merge
(EntityManager entityManager, Class<T> root, Stream<? extends Graph<T>> graphs) Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.static <R> void
setFetchGraph
(TypedQuery<R> query, EntityGraph<R> graph) Convenience method to apply the given fetch graph to the given query without the need for a cast when working with JPA API.static <R> void
setGraph
(TypedQuery<R> query, EntityGraph<R> graph, GraphSemantic semantic) Convenience method to apply the given graph to the given query without the need for a cast when working with JPA API.static <R> void
setLoadGraph
(TypedQuery<R> query, EntityGraph<R> graph) Convenience method to apply the given load graph to the given query without the need for a cast when working with JPA API.
-
Constructor Details
-
EntityGraphs
public EntityGraphs()
-
-
Method Details
-
createGraph
Create a new entity graph rooted at the given entity, without needing a reference to the session or session factory.- Parameters:
rootType
- TheEntityType
representing the root entity of the graph- Returns:
- a new mutable
EntityGraph
- Since:
- 7.0
-
createGraphForDynamicEntity
Create a new entity graph rooted at the given dynamic entity, without needing a reference to the session or session factory.- Parameters:
rootType
- TheEntityType
representing the root entity of the graph, which must be a dynamic entity- Returns:
- a new mutable
EntityGraph
- Since:
- 7.0
-
merge
@SafeVarargs public static <T> EntityGraph<T> merge(EntityManager entityManager, Class<T> root, Graph<T>... graphs) Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.- Type Parameters:
T
- Root entity type of the query and graph.- Parameters:
entityManager
-EntityManager
to use to create the new merged graph.root
- Root type of the entity for which the graph is being merged.graphs
- Graphs to merge.- Returns:
- The merged graph.
-
merge
public static <T> EntityGraph<T> merge(EntityManager entityManager, Class<T> root, List<? extends Graph<T>> graphs) Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.- Type Parameters:
T
- Root entity type of the query and graph.- Parameters:
entityManager
-EntityManager
to use to create the new merged graph.root
- Root type of the entity for which the graph is being merged.graphs
- Graphs to merge.- Returns:
- The merged graph.
- Since:
- 7.0
-
merge
public static <T> EntityGraph<T> merge(EntityManager entityManager, Class<T> root, Stream<? extends Graph<T>> graphs) Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.- Type Parameters:
T
- Root entity type of the query and graph.- Parameters:
entityManager
-EntityManager
to use to create the new merged graph.root
- Root type of the entity for which the graph is being merged.graphs
- Graphs to merge.- Returns:
- The merged graph.
- Since:
- 7.0
-
setGraph
Convenience method to apply the given graph to the given query without the need for a cast when working with JPA API.- Parameters:
query
- The JPATypedQuery
graph
- The JPAEntityGraph
to applysemantic
- The semantic to use when applying the graph- Since:
- 7.0
- See Also:
-
setLoadGraph
Convenience method to apply the given load graph to the given query without the need for a cast when working with JPA API.- Parameters:
query
- The JPATypedQuery
graph
- The JPAEntityGraph
to apply- Since:
- 7.0
-
setFetchGraph
Convenience method to apply the given fetch graph to the given query without the need for a cast when working with JPA API.- Parameters:
query
- The JPATypedQuery
graph
- The JPAEntityGraph
to apply- Since:
- 7.0
-
addTreatedSubgraph
Allows a treated subgraph to ve created for aSubgraph
, since the JPA-standard operationEntityGraph.addTreatedSubgraph(Class)
is declared byEntityGraph
.- Parameters:
graph
- any root graph or subgraphsubtype
- the treated (narrowed) type- Since:
- 7.0
-
executeList
@Deprecated(since="7.0") public static List executeList(Query query, EntityGraph<?> graph, GraphSemantic semantic) Deprecated.Since it is not type safe and returns a raw typeConvenience method for executing the query, applying the givenEntityGraph
using the specified semantic- Parameters:
query
- The JPA Querygraph
- The graph to applysemantic
- The semantic to use when applying the graph
-
executeList
@Deprecated(since="7.0") public static <R> List<R> executeList(TypedQuery<R> query, EntityGraph<R> graph, GraphSemantic semantic) Deprecated.UsesetGraph(TypedQuery, EntityGraph, GraphSemantic)
insteadForm ofexecuteList(Query, EntityGraph, GraphSemantic)
accepting aTypedQuery
.- Parameters:
query
- The JPA Querygraph
- The graph to applysemantic
- The semantic to use when applying the graph- API Note:
- This signature assumes that the Query's return is an entity and that the graph applies to that entity's type. JPA does not necessarily require that, but it is by far the most common usage.
-
executeList
@Deprecated(since="7.0") public static List executeList(Query query, EntityGraph<?> graph, String semanticJpaHintName) Deprecated.Since it is not type safe, returns a raw type, and accepts a stringConvenience method for executing the query, applying the givenEntityGraph
using the named semantic using JPA's "hint name". SeeGraphSemantic.fromHintName(java.lang.String)
.- Parameters:
query
- The JPA Querygraph
- The graph to applysemanticJpaHintName
- SeeGraphSemantic.fromHintName(java.lang.String)
- Returns:
- The result list
-
executeList
@Deprecated(since="7.0") public static <R> List<R> executeList(TypedQuery<R> query, EntityGraph<R> graph, String semanticJpaHintName) Deprecated.Since it accepts a string instead ofGraphSemantic
Form ofexecuteList(Query, EntityGraph, String)
accepting aTypedQuery
.- Parameters:
query
- The JPA Querygraph
- The graph to applysemanticJpaHintName
- SeeGraphSemantic.fromHintName(java.lang.String)
- API Note:
- This signature assumes that the Query's return is an entity and that the graph applies to that entity's type. JPA does not necessarily require that, but it is by far the most common usage.
-
executeList
Deprecated.Since it is not type safe and returns a raw typeConvenience method for executing the query using the givenEntityGraph
.- Parameters:
query
- The JPA Querygraph
- The graph to apply- API Note:
- Operates on the assumption that the "default" semantic for an
entity graph applied to a query is
GraphSemantic.FETCH
. This is simply knowledge from JPA EG discussions, nothing that is specifically mentioned or discussed in the spec.
-
executeList
@Deprecated(since="7.0") public static <R> List<R> executeList(TypedQuery<R> query, EntityGraph<R> graph) Deprecated.UsesetFetchGraph(TypedQuery, EntityGraph)
insteadForm ofexecuteList(Query, EntityGraph, String)
accepting aTypedQuery
.- Parameters:
query
- The JPA Querygraph
- The graph to apply- API Note:
- This signature assumes that the Query's return is an entity and that the graph applies to that entity's type. JPA does not necessarily require that, but it is by far the most common usage.
-
areEqual
Compares two entity graphs and returnstrue
if they are equal, ignoring attribute order.- Type Parameters:
T
- Root entity type of BOTH graphs.- Parameters:
a
- Graph to compare.b
- Graph to compare.
-
areEqual
Compares two entity graph attribute node and returnstrue
if they are equal, ignoring subgraph attribute order. -
areEqual
Compares two entity subgraph maps and returnstrue
if they are equal, ignoring order. -
areEqual
Compares two entity subgraphs and returnstrue
if they are equal, ignoring attribute order.
-