Skip to content

Commit 675d5ef

Browse files
committed
warn people in javadoc that inSession() and friends don't flush!
1 parent bc4d78b commit 675d5ef

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

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

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,19 @@ public interface SessionFactory extends EntityManagerFactory, Referenceable, Ser
227227
StatelessSession openStatelessSession(Connection connection);
228228

229229
/**
230-
* Open a {@link Session} and use it to perform an action.
230+
* Open a {@link Session} and use it to perform the given action.
231+
*
232+
* @apiNote This method does not begin a transaction, and so
233+
* the session is not automatically flushed before the method
234+
* returns unless either:
235+
* <ul>
236+
* <li>the given action calls {@link Session#flush() flush()}
237+
* explicitly, or
238+
* <li>a transaction is initiated by the given action, using
239+
* {@link Session#inTransaction}, for example.
240+
* </ul>
241+
*
242+
* @see #inTransaction(Consumer)
231243
*/
232244
default void inSession(Consumer<? super Session> action) {
233245
try ( Session session = openSession() ) {
@@ -236,7 +248,20 @@ default void inSession(Consumer<? super Session> action) {
236248
}
237249

238250
/**
239-
* Open a {@link StatelessSession} and use it to perform an action.
251+
* Open a {@link StatelessSession} and use it to perform the
252+
* given action.
253+
*
254+
* @apiNote This method does not begin a transaction, and so
255+
* the session is not automatically flushed before the method
256+
* returns unless either:
257+
* <ul>
258+
* <li>the given action calls {@link Session#flush() flush()}
259+
* explicitly, or
260+
* <li>a transaction is initiated by the given action, using
261+
* {@link Session#inTransaction}, for example.
262+
* </ul>
263+
*
264+
* @see #inStatelessTransaction(Consumer)
240265
*
241266
* @since 6.3
242267
*/
@@ -247,7 +272,7 @@ default void inStatelessSession(Consumer<? super StatelessSession> action) {
247272
}
248273

249274
/**
250-
* Open a {@link Session} and use it to perform an action
275+
* Open a {@link Session} and use it to perform the given action
251276
* within the bounds of a transaction.
252277
*
253278
* @apiNote This method competes with the JPA-defined method
@@ -269,6 +294,18 @@ default void inStatelessTransaction(Consumer<? super StatelessSession> action) {
269294

270295
/**
271296
* Open a {@link Session} and use it to obtain a value.
297+
*
298+
* @apiNote This method does not begin a transaction, and so
299+
* the session is not automatically flushed before the method
300+
* returns unless either:
301+
* <ul>
302+
* <li>the given action calls {@link Session#flush() flush()}
303+
* explicitly, or
304+
* <li>a transaction is initiated by the given action, using
305+
* {@link Session#inTransaction}, for example.
306+
* </ul>
307+
*
308+
* @see #fromTransaction(Function)
272309
*/
273310
default <R> R fromSession(Function<? super Session,R> action) {
274311
try ( Session session = openSession() ) {
@@ -279,6 +316,18 @@ default <R> R fromSession(Function<? super Session,R> action) {
279316
/**
280317
* Open a {@link StatelessSession} and use it to obtain a value.
281318
*
319+
* @apiNote This method does not begin a transaction, and so
320+
* the session is not automatically flushed before the method
321+
* returns unless either:
322+
* <ul>
323+
* <li>the given action calls {@link Session#flush() flush()}
324+
* explicitly, or
325+
* <li>a transaction is initiated by the given action, using
326+
* {@link Session#inTransaction}, for example.
327+
* </ul>
328+
*
329+
* @see #fromStatelessTransaction(Function)
330+
*
282331
* @since 6.3
283332
*/
284333
default <R> R fromStatelessSession(Function<? super StatelessSession,R> action) {

0 commit comments

Comments
 (0)