You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: documentation/src/main/asciidoc/repositories/Repositories.adoc
+21-1Lines changed: 21 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -87,17 +87,27 @@ The following table contrasts the two programming models.
87
87
| SQL execution | During flush | Immediate
88
88
| Updates | Usually implicit (dirty checking during flush) | Always explicit (by calling `@Update` method)
89
89
| Operation cascading | Depends on `CascadeType` | Never
90
+
| Lazy fetching | Implicit | Explicit using link:{doc-javadoc-url}org/hibernate/StatelessSession.html#fetch(java.lang.Object)[`StatelessSession.fetch()`]
90
91
| Validation of JPQL | Runtime | Compile time
91
92
|===
92
93
93
94
The fundamental difference here that Jakarta Data does not feature stateful persistence contexts.
94
95
Among other consequences:
95
96
96
97
- entity instances are always detached, and so
97
-
- updates require an explicit operation.
98
+
- updates require an explicit operation, and
99
+
- there's no transparent lazy association fetching.
98
100
99
101
It's important to understand that a repository in Hibernate Data Repositories is backed by a `StatelessSession`, not by a Jakarta Persistence `EntityManager`.
100
102
103
+
[IMPORTANT]
104
+
====
105
+
There's only one portable way to fetch an association in Jakarta Data, and that's by using a JPQL `join fetch` clause, in a <<query-method,`@Query` annotation>>.
106
+
The specification does not provide a portable way to fetch an association lazily.
107
+
To fetch an association, we need to <<stateless-fetch,call the `StatelessSession` directly>>.
108
+
This really isn't as bad as it sounds; overuse of lazy fetching is associated with poor performance due to many round trips to the database server.
109
+
====
110
+
101
111
[NOTE]
102
112
====
103
113
A future release of Jakarta Data will feature repositories backed by Jakarta Persistence stateful persistence contexts, but this functionality did not make the cut for Jakarta Data 1.0.
0 commit comments