8000 properly document EnabledFetchProfile · hibernate/hibernate-orm@e4e8482 · GitHub
[go: up one dir, main page]

Skip to content

Commit e4e8482

Browse files
committed
properly document EnabledFetchProfile
1 parent e9a9723 commit e4e8482

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

documentation/src/main/asciidoc/introduction/Advanced.adoc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1140,14 +1140,21 @@ We may define as many different fetch profiles as we like.
11401140
| `@FetchProfileOverride` | Specifies the fetch strategy for the annotated association, in a given fetch profile
11411141
|===
11421142

1143-
A fetch profile must be explicitly enabled for a given session by calling link:{doc-javadoc-url}org/hibernate/Session.html#enableFetchProfile(java.lang.String)[`enableFetchProfile()`]:
1143+
A fetch profile must be explicitly enabled for a given session by passing the name of the profile to link:{doc-javadoc-url}org/hibernate/Session.html#enableFetchProfile(java.lang.String)[`enableFetchProfile()`]:
11441144

11451145
[source,java]
11461146
----
11471147
session.enableFetchProfile(Book_.PROFILE_EAGER_BOOK);
11481148
Book eagerBook = session.find(Book.class, bookId);
11491149
----
11501150

1151+
Alternatively, an instance of link:{doc-javadoc-url}org/hibernate/EnabledFetchProfile.html[`EnabledFetchProfile`] may be obtained in a type safe way from the static metamodel, and used as a `FindOption`:
1152+
1153+
[source,java]
1154+
----
1155+
Book eagerBook = entityManager.find(Book.class, bookId, Book_._EagerBook);
1156+
----
1157+
11511158
So why or when might we prefer named fetch profiles to entity graphs?
11521159
Well, it's really hard to say.
11531160
It's nice that this feature _exists_, and if you love it, that's great.

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,41 @@
99
/**
1010
* A {@link jakarta.persistence.FindOption} which requests a named
1111
* {@linkplain org.hibernate.annotations.FetchProfile fetch profile}.
12+
* <p>
13+
* An instance of this class may be obtained in a type safe way
14+
* from the static metamodel for the class annotated
15+
* {@link org.hibernate.annotations.FetchProfile @FetchProfile}
16+
* and passed as an option to
17+
* {@link Session#find(Class, Object, FindOption...) find()}.
18+
* <p>
19+
* For example, this class defines a fetch profile:
20+
* <pre>
21+
* &#064;Entity
22+
* &#064;FetchProfile(name = "WithAuthors")
23+
* class Book {
24+
* ...
1225
*
13-
* @param profileName the {@link org.hibernate.annotations.FetchProfile#name()}
26+
* &#064;ManyToMany
27+
* &#064;FetchProfileOverride(profile = Book_.PROFILE_WITH_AUTHORS)
28+
* Set&lt;Author&gt; authors;
29+
* }
30+
* </pre>
31+
* The fetch profile may be requested like this:
32+
* <pre>
33+
* Book bookWithAuthors =
34+
* session.find(Book.class, isbn, Book_._WithAuthors)
35+
* </pre>
36+
* <p>
37+
* When the static metamodel is not used, an {@code EnabledFetchProfile}
38+
* may be instantiated directly, passing the name of the fetch profile
39+
* as a string.
40+
* <pre>
41+
* Book bookWithAuthors =
42+
* session.find(Book.class, isbn,
43+
* new EnabledFetchProfile("WithAuthors"))
44+
* </pre>
45+
*
46+
* @param profileName the {@linkplain org.hibernate.annotations.FetchProfile#name profile name}
1447
*
1548
* @since 7.0
1649
*

hibernate-core/src/main/java/org/hibernate/annotations/FetchProfileOverride.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
FetchType fetch() default EAGER;
5555

5656
/**
57-
* The name of the {@link FetchProfile fetch profile} in
58-
* which this fetch mode should be applied.
57+
* The name of the {@linkplain FetchProfile fetch profile}
58+
* in which this fetch mode should be applied.
5959
*/
6060
String profile();
6161
}

0 commit comments

Comments
 (0)
0