Skip to content

Commit 0ea5bd8

Browse files
committed
HHH-19216 - NamedEntityGraph annotation supporting Hibernate parseable format
HHH-19237 - Expand graph language to optionally specify entity HHH-19217 - Expose GraphParser#parse on SessionFactory
1 parent ca1eb99 commit 0ea5bd8

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

documentation/src/main/asciidoc/userguide/chapters/fetching/Fetching.adoc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ the subtype Class.
285285
Hibernate allows the creation of Jakarta Persistence fetch/load graphs by parsing a textual representation
286286
of the graph. Generally speaking, the textual representation of a graph is a comma-separated
287287
list of attribute names, optionally including any subgraph specifications.
288-
`org.hibernate.graph.GraphParser` is the starting point for such parsing operations.
288+
The starting point for such parsing operations is either `org.hibernate.graph.GraphParser`
289+
or `SessionFactory#parseEntityGraph`
289290

290291
[NOTE]
291292
====
@@ -370,6 +371,28 @@ include::{example-dir-fetching}/GraphParsingTest.java[tags=fetching-strategies-d
370371
====
371372

372373

374+
[[fetching-strategies-dynamic-fetching-entity-graph-parsing-annotation]]
375+
==== @NamedEntityGraph with text representation
376+
377+
Hibernate also offers a `@org.hibernate.annotations.NamedEntityGraph` annotation, as a corollary
378+
to the `@jakarta.persistence.NamedEntityGraph`, supporting the text representation
379+
<<fetching-strategies-dynamic-fetching-entity-graph-parsing,discussed previously>>. The annotation
380+
may be placed on an entity or on a package.
381+
382+
383+
.@NamedEntityGraph example
384+
====
385+
[source, java, indent=0]
386+
----
387+
@Entity
388+
@NamedEntityGraph( graph="title,isbn,author(name,phoneNumber)" )
389+
class Book {
390+
// ...
391+
}
392+
----
393+
====
394+
395+
373396
[[fetching-strategies-dynamic-fetching-profile]]
374397
=== Dynamic fetching via Hibernate profiles
375398

hibernate-core/src/main/java/org/hibernate/metamodel/model/domain/internal/JpaMetamodelImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ private <T> ImportInfo<T> resolveImport(final String name) {
491491
}
492492
}
493493

494-
private void applyNamedEntityGraphs(Collection<NamedEntityGraphDefinition> namedEntityGraphs, RuntimeModelCreationContext runtimeModelCreationContext) {
494+
private void applyNamedEntityGraphs(Collection<NamedEntityGraphDefinition> namedEntityGraphs) {
495495
for ( NamedEntityGraphDefinition definition : namedEntityGraphs ) {
496496
log.debugf(
497497
"Applying named entity graph [name=%s, source=%s]",
@@ -680,7 +680,7 @@ public void processJpa(
680680
}
681681
} );
682682

683-
applyNamedEntityGraphs( namedEntityGraphDefinitions, runtimeModelCreationContext );
683+
applyNamedEntityGraphs( namedEntityGraphDefinitions );
684684

685685
populateStaticMetamodel( bootMetamodel, context );
686686
}

migration-guide.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ earlier versions, see any other pertinent migration guides as well.
3434
See this https://in.relation.to/2024/04/01/jakarta-persistence-3/[blog post] for a good discussion of the changes in Jakarta Persistence 3.2.
3535

3636

37+
[[NamedEntityGraph]]
38+
== @NamedEntityGraph
39+
40+
A new annotation (`@org.hibernate.annotations.NamedEntityGraph`) has been added to allow
41+
specifying a named entity-graph using Hibernate's ability to parse a string representation of the graph.
42+
43+
44+
[source,java]
45+
----
46+
@Entity
47+
@NamedEntityGraph( graph="title, isbn, author( name, phoneNumber )" )
48+
class Book {
49+
// ...
50+
}
51+
----
52+
53+
54+
See `org.hibernate.graph.GraphParser` for details on the syntax and the
55+
link:{user-guide-url}#fetching-strategies-dynamic-fetching-entity-graph-parsing-annotation[user guide] for additional details.
56+
57+
58+
3759
[[hibernate-models]]
3860
== Hibernate Models
3961

0 commit comments

Comments
 (0)