Skip to content

Commit 4115f97

Browse files
committed
improve the Javadoc for EntityGraph-related methods of Session
1 parent eca53a2 commit 4115f97

File tree

2 files changed

+87
-15
lines changed

2 files changed

+87
-15
lines changed

hibernate-core/src/main/java/org/hibernate/Session.java

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1252,8 +1252,8 @@ public interface Session extends SharedSessionContract, EntityManager {
12521252
LobHelper getLobHelper();
12531253

12541254
/**
1255-
* Obtain a {@link Session} builder with the ability to copy certain information
1256-
* from this session.
1255+
* Obtain a {@link Session} builder with the ability to copy certain
1256+
* information from this session.
12571257
*
12581258
* @return the session builder
12591259
*/
@@ -1266,15 +1266,66 @@ public interface Session extends SharedSessionContract, EntityManager {
12661266
*/
12671267
void addEventListeners(SessionEventListener... listeners);
12681268

1269+
/**
1270+
* Create a new mutable instance of {@link EntityGraph}, with only
1271+
* a root node, allowing programmatic definition of the graph from
1272+
* scratch.
1273+
*
1274+
* @param rootType The root entity of the graph
1275+
*
1276+
* @see #find(EntityGraph, Object, FindOption...)
1277+
* @see org.hibernate.query.SelectionQuery#setEntityGraph(EntityGraph, org.hibernate.graph.GraphSemantic)
1278+
* @see org.hibernate.graph.EntityGraphs#createGraph(jakarta.persistence.metamodel.EntityType)
1279+
*/
12691280
@Override
12701281
<T> RootGraph<T> createEntityGraph(Class<T> rootType);
12711282

1283+
/**
1284+
* Create a new mutable instance of {@link EntityGraph}, based on
1285+
* a predefined {@linkplain jakarta.persistence.NamedEntityGraph
1286+
* named entity graph}, allowing customization of the graph, or
1287+
* return {@code null} if there is no predefined graph with the
1288+
* given name.
1289+
*
1290+
* @param graphName The name of the predefined named entity graph
1291+
*
1292+
* @apiNote This method returns {@code RootGraph<?>}, requiring an
1293+
* unchecked typecast before use. It's cleaner to obtain a graph using
1294+
* {@link #createEntityGraph(Class, String)} instead.
1295+
*
1296+
* @see #find(EntityGraph, Object, FindOption...)
1297+
* @see org.hibernate.query.SelectionQuery#setEntityGraph(EntityGraph, org.hibernate.graph.GraphSemantic)
1298+
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
1299+
*/
12721300
@Override
12731301
RootGraph<?> createEntityGraph(String graphName);
12741302

1303+
/**
1304+
* Obtain an immutable reference to a predefined
1305+
* {@linkplain jakarta.persistence.NamedEntityGraph named entity graph}
1306+
* or return {@code null} if there is no predefined graph with the given
1307+
* name.
1308+
*
1309+
* @param graphName The name of the predefined named entity graph
1310+
*
1311+
* @apiNote This method returns {@code RootGraph<?>}, requiring an
1312+
* unchecked typecast before use. It's cleaner to obtain a graph using
1313+
* the static metamodel for the class which defines the graph, or by
1314+
* calling {@link SessionFactory#getNamedEntityGraphs(Class)} instead.
1315+
*
1316+
* @see #find(EntityGraph, Object, FindOption...)
1317+
* @see org.hibernate.query.SelectionQuery#setEntityGraph(EntityGraph, org.hibernate.graph.GraphSemantic)
1318+
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
1319+
*/
12751320
@Override
12761321
RootGraph<?> getEntityGraph(String graphName);
12771322

1323+
/**
1324+
* Retrieve all named {@link EntityGraph}s with the given root entity type.
1325+
*
1326+
* @see jakarta.persistence.EntityManagerFactory#getNamedEntityGraphs(Class)
1327+
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
1328+
*/
12781329
@Override
12791330
<T> List<EntityGraph<? super T>> getEntityGraphs(Class<T> entityClass);
12801331

hibernate-core/src/main/java/org/hibernate/SharedSessionContract.java

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -314,34 +314,47 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
314314
<T> T doReturningWork(ReturningWork<T> work);
315315

316316
/**
317-
* Create a new mutable {@link EntityGraph} with only a root node.
317+
* Create a new mutable instance of {@link EntityGraph}, with only
318+
* a root node, allowing programmatic definition of the graph from
319+
* scratch.
318320
*
319321
* @param rootType the root entity class of the graph
320322
*
321323
* @since 6.3
324+
*
325+
* @see org.hibernate.graph.EntityGraphs#createGraph(jakarta.persistence.metamodel.EntityType)
322326
*/
323327
<T> RootGraph<T> createEntityGraph(Class<T> rootType);
324328

325329
/**
326-
* Create a new mutable copy of the named {@link EntityGraph},
327-
* or return {@code null} if there is no graph with the given
328-
* name.
330+
* Create a new mutable instance of {@link EntityGraph}, based on
331+
* a predefined {@linkplain jakarta.persistence.NamedEntityGraph
332+
* named entity graph}, allowing customization of the graph, or
333+
* return {@code null} if there is no predefined graph with the
334+
* given name.
329335
*
330336
* @param graphName the name of the graph
331337
*
338+
* @apiNote This method returns {@code RootGraph<?>}, requiring an
339+
* unchecked typecast before use. It's cleaner to obtain a graph using
340+
* {@link #createEntityGraph(Class, String)} instead.
341+
*
342+
* @see SessionFactory#getNamedEntityGraphs(Class)
332343
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
333344
*
334345
* @since 6.3
335346
*/
336347
RootGraph<?> createEntityGraph(String graphName);
337348

338349
/**
339-
* Create a new mutable copy of the named {@link EntityGraph},
340-
* or return {@code null} if there is no graph with the given
341-
* name.
350+
* Create a new mutable instance of {@link EntityGraph}, based on
351+
* a predefined {@linkplain jakarta.persistence.NamedEntityGraph
352+
* named entity graph}, allowing customization of the graph, or
353+
* return {@code null} if there is no predefined graph with the
354+
* given name.
342355
*
343356
* @param rootType the root entity class of the graph
344-
* @param graphName the name of the graph
357+
* @param graphName the name of the predefined named entity graph
345358
*
346359
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
347360
*
@@ -353,21 +366,29 @@ public interface SharedSessionContract extends QueryProducer, AutoCloseable, Ser
353366
<T> RootGraph<T> createEntityGraph(Class<T> rootType, String graphName);
354367

355368
/**
356-
* Retrieve the named {@link EntityGraph} as an immutable graph,
357-
* or return {@code null} if there is no graph with the given
369+
* Obtain an immutable reference to a predefined
370+
* {@linkplain jakarta.persistence.NamedEntityGraph named entity graph}
371+
* or return {@code null} if there is no predefined graph with the given
358372
* name.
359373
*
360-
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
374+
* @param graphName the name of the predefined named entity graph
361375
*
362-
* @param graphName the name of the graph
376+
* @apiNote This method returns {@code RootGraph<?>}, requiring an
377+
* unchecked typecast before use. It's cleaner to obtain a graph using
378+
* the static metamodel for the class which defines the graph, or by
379+
* calling {@link SessionFactory#getNamedEntityGraphs(Class)} instead.
380+
*
381+
* @see SessionFactory#getNamedEntityGraphs(Class)
382+
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
363383
*
364384
* @since 6.3
365385
*/
366386
RootGraph<?> getEntityGraph(String graphName);
367387

368388
/**
369-
* Retrieve all named {@link EntityGraph}s with the given type.
389+
* Retrieve all named {@link EntityGraph}s with the given root entity type.
370390
*
391+
* @see jakarta.persistence.EntityManagerFactory#getNamedEntityGraphs(Class)
371392
* @see jakarta.persistence.EntityManagerFactory#addNamedEntityGraph(String, EntityGraph)
372393
*
373394
* @since 6.3

0 commit comments

Comments
 (0)