Skip to content

Commit cb05349

Browse files
Fabian Baumeisterbaumeister25
Fabian Baumeister
authored andcommitted
feat: Extend FetchType documentation
In HH the feedback was raised, that always LazyLoading is not correct, but depends on the use case. Therefore, a link describing the differences and an exceptional case for EAGER was added.
1 parent 3c8c42e commit cb05349

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

modules/ROOT/pages/persistence/jpa.adoc

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ Byte array will cause problems if BLOBs get large because the entire BLOB is loa
5353
* Always use link:https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/temporaltype[`TemporalType.TIMESTAMP`] with link:https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/temporal[`@Temporal`].
5454
* Mixing with other granularities causes problems when comparing one value to another.
5555

56-
=== Always use lazy loading
56+
=== Consider the fetch type of relations
5757

58-
Application are strongly advised to always use lazy loading. Always override the default of the relationship annotation by providing link:https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/manytomany#fetch()[`fetch = FetchType.LAZY`], even if this is the default already.
58+
When creating a relation between entities, the correct fetch type should be always considered for the use case. The difference between the two types eager and lazy loading is described link:https://www.baeldung.com/hibernate-lazy-eager-loading[here].
59+
Applications are strongly advised to use lazy loading, except it's 100% clear that eager loading is necessary in all cases.
60+
Always override the default of the relationship annotation by providing the selected link:https://jakarta.ee/specifications/persistence/3.1/apidocs/jakarta.persistence/jakarta/persistence/manytomany#fetch()[FetchType] explicitly, to make it transparent for future developers.
5961

6062
=== Map enums to dedicated string
6163

0 commit comments

Comments
 (0)