Top Description Constructors Methods
org.hibernate.graph

public final Class EntityGraphs

extends Object
Class Inheritance
Imports
java.util.List, .Map, .Set, jakarta.persistence.AttributeNode, .EntityGraph, .EntityManager, .Query, .Subgraph, .TypedQuery, org.hibernate.Session, org.hibernate.engine.spi.SessionImplementor, org.hibernate.graph.spi.GraphImplementor, .RootGraphImplementor

A collection of EntityGraph utilities.

API Note

These methods really belong inside other classes that we cannot modify.

Author
asusnjar

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static <
Root entity type of BOTH graphs.
T
>
boolean
areEqual(EntityGraph<T>
Graph to compare.
a
,
EntityGraph<T>
Graph to compare.
b
)

Compares two entity graphs and returns true if they are equal, ignoring attribute order.

public static boolean
areEqual(AttributeNode<?> a, AttributeNode<?> b)

Compares two entity graph attribute node and returns true if they are equal, ignoring subgraph attribute order.

public static boolean
areEqual(Map<Class<T>, Subgraph<T>> a, Map<Class<T>, Subgraph<T>> b)

Compares two entity subgraph maps and returns true if they are equal, ignoring order.

public static boolean
areEqual(Subgraph<T> a, Subgraph<T> b)

Compares two entity subgraphs and returns true if they are equal, ignoring attribute order.

public static List<E>
executeList(Query
The JPA Query
query
,
EntityGraph<T>
The graph to apply
graph
,
GraphSemantic
The semantic to use when applying the graph
semantic
)

Convenience method for executing the query, applying the given EntityGraph using the specified semantic

public static <R> List<R>
executeList(TypedQuery<R>
The JPA Query
query
,
EntityGraph<R>
The graph to apply
graph
,
GraphSemantic
The semantic to use when applying the graph
semantic
)

Form of executeList(Query, EntityGraph, GraphSemantic) accepting a TypedQuery.

public static List<E>

Returns:

The result list
executeList
(Query
The JPA Query
query
,
EntityGraph<T>
The graph to apply
graph
,
String semanticJpaHintName)

Convenience method for executing the query, applying the given EntityGraph using the named semantic using JPA's "hint name".

public static <R> List<R>
executeList(TypedQuery<R>
The JPA Query
query
,
EntityGraph<R>
The graph to apply
graph
,
String semanticJpaHintName)

Form of executeList(Query, EntityGraph, String) accepting a TypedQuery.

public static List<E>
executeList(Query
The JPA Query
query
,
EntityGraph<T>
The graph to apply
graph
)

Convenience method for executing the query using the given EntityGraph.

public static <R> List<R>
executeList(TypedQuery<R>
The JPA Query
query
,
EntityGraph<R>
The graph to apply
graph
)

Form of executeList(Query, EntityGraph, String) accepting a TypedQuery.

public static <
Root entity type of the query and graph.
T
>
EntityGraph<T>

Returns:

The merged graph.
merge
(EntityManager
EntityManager to use to create the new merged graph.
em
,
Class<T>
Root type of the entity for which the graph is being merged.
rootType
,
EntityGraph<T>...
Graphs to merge.
graphs
)

Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.

public static <T> EntityGraph<T>
merge(Session session, Class<T> rootType, Graph<T>... graphs)

public static <T> EntityGraph<T>
merge(SessionImplementor session, Class<T> rootType, GraphImplementor<T>... graphs)

private static <T> EntityGraph<T>
merge(SessionImplementor session, Class<T> rootType, Object... graphs)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

EntityGraphsback to summary
public EntityGraphs()

Method Detail

areEqualback to summary
public static <T> boolean areEqual(EntityGraph<T> a, EntityGraph<T> b)

Compares two entity graphs and returns true if they are equal, ignoring attribute order.

Parameters
<T>
Root entity type of BOTH graphs.
a:EntityGraph<T>

Graph to compare.

b:EntityGraph<T>

Graph to compare.

areEqualback to summary
public static boolean areEqual(AttributeNode<?> a, AttributeNode<?> b)

Compares two entity graph attribute node and returns true if they are equal, ignoring subgraph attribute order.

areEqualback to summary
public static boolean areEqual(Map<Class<T>, Subgraph<T>> a, Map<Class<T>, Subgraph<T>> b)

Compares two entity subgraph maps and returns true if they are equal, ignoring order.

areEqualback to summary
public static boolean areEqual(Subgraph<T> a, Subgraph<T> b)

Compares two entity subgraphs and returns true if they are equal, ignoring attribute order.

executeListback to summary
public static List<E> executeList(Query query, EntityGraph<T> graph, GraphSemantic semantic)

Convenience method for executing the query, applying the given EntityGraph using the specified semantic

Parameters
query:Query

The JPA Query

graph:EntityGraph<T>

The graph to apply

semantic:GraphSemantic

The semantic to use when applying the graph

Annotations
@SuppressWarnings:unchecked
executeListback to summary
public static <R> List<R> executeList(TypedQuery<R> query, EntityGraph<R> graph, GraphSemantic semantic)

Form of executeList(Query, EntityGraph, GraphSemantic) accepting a TypedQuery.

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.

Parameters
query:TypedQuery<R>

The JPA Query

graph:EntityGraph<R>

The graph to apply

semantic:GraphSemantic

The semantic to use when applying the graph

Annotations
@SuppressWarnings:unused, unchecked
executeListback to summary
public static List<E> executeList(Query query, EntityGraph<T> graph, String semanticJpaHintName)

Convenience method for executing the query, applying the given EntityGraph using the named semantic using JPA's "hint name". See GraphSemantic#fromHintName.

Parameters
query:Query

The JPA Query

graph:EntityGraph<T>

The graph to apply

semanticJpaHintName:String

See GraphSemantic#fromHintName

Returns:List<E>

The result list

Annotations
@SuppressWarnings:unused, unchecked
executeListback to summary
public static <R> List<R> executeList(TypedQuery<R> query, EntityGraph<R> graph, String semanticJpaHintName)

Form of executeList(Query, EntityGraph, String) accepting a TypedQuery.

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.

Parameters
query:TypedQuery<R>

The JPA Query

graph:EntityGraph<R>

The graph to apply

semanticJpaHintName:String

See GraphSemantic#fromHintName

Annotations
@SuppressWarnings:unused, unchecked
executeListback to summary
public static List<E> executeList(Query query, EntityGraph<T> graph)

Convenience method for executing the query using the given EntityGraph.

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.

Parameters
query:Query

The JPA Query

graph:EntityGraph<T>

The graph to apply

Annotations
@SuppressWarnings:unused, unchecked
executeListback to summary
public static <R> List<R> executeList(TypedQuery<R> query, EntityGraph<R> graph)

Form of executeList(Query, EntityGraph, String) accepting a TypedQuery.

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.

Parameters
query:TypedQuery<R>

The JPA Query

graph:EntityGraph<R>

The graph to apply

Annotations
@SuppressWarnings:unused
mergeback to summary
public static <T> EntityGraph<T> merge(EntityManager em, Class<T> rootType, EntityGraph<T>... graphs)

Merges multiple entity graphs into a single graph that specifies the fetching/loading of all attributes the input graphs specify.

Parameters
<T>
Root entity type of the query and graph.
em:EntityManager

EntityManager to use to create the new merged graph.

rootType:Class<T>

Root type of the entity for which the graph is being merged.

graphs:EntityGraph<T>[]

Graphs to merge.

Returns:EntityGraph<T>

The merged graph.

Annotations
@SuppressWarnings:unchecked
mergeback to summary
public static <T> EntityGraph<T> merge(Session session, Class<T> rootType, Graph<T>... graphs)
Annotations
@SafeVarargs
mergeback to summary
public static <T> EntityGraph<T> merge(SessionImplementor session, Class<T> rootType, GraphImplementor<T>... graphs)
Annotations
@SafeVarargs
mergeback to summary
private static <T> EntityGraph<T> merge(SessionImplementor session, Class<T> rootType, Object... graphs)
Annotations
@SuppressWarnings:unchecked