Skip to content

Commit 7a7910c

Browse files
committed
add clarifications as recommended by @sebersole
1 parent 0b64805 commit 7a7910c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,33 @@
3535
* and does not force a version increment.
3636
* <p>
3737
* When an entity is read from the database, its lock mode
38-
* determines whether lost updates and non-repeatable reads
39-
* are possible.
38+
* determines whether lost updates and non-repeatable reads are
39+
* possible. Assuming the underlying transaction isolation
40+
* {@linkplain java.sql.Connection#getTransactionIsolation level}
41+
* of the current JDBC database connection is at least
42+
* {@linkplain java.sql.Connection#TRANSACTION_READ_COMMITTED
43+
* read committed}, then:
4044
* <ul>
4145
* <li>{@link #NONE} and {@link #READ} prevent lost updates
4246
* only for versioned entities, but do not prevent
4347
* non-repeatable reads, and do not prevent lost updates
44-
* for entities with no version attribute.
48+
* for entities with no version attribute;
4549
* <li>{@link #OPTIMISTIC} and {@link #OPTIMISTIC_FORCE_INCREMENT}
4650
* prevent lost updates and non-repeatable reads only for
47-
* versioned entities.
51+
* versioned entities;
4852
* <li>{@link #PESSIMISTIC_READ}, {@link #PESSIMISTIC_WRITE},
4953
* and {@link #PESSIMISTIC_FORCE_INCREMENT} prevent lost
5054
* updates and non-repeatable reads for all entities,
5155
* including entities with no version attribute.
5256
* </ul>
5357
* <p>
58+
* Regardless of the lock mode of a given entity, a non-repeatable
59+
* read is always possible when {@link Session#refresh(Object)}
60+
* is called for that entity, except when the underlying transaction
61+
* isolation level of the current JDBC database connection is at
62+
* least {@linkplain java.sql.Connection#TRANSACTION_REPEATABLE_READ
63+
* repeatable read}.
64+
* <p>
5465
* This enumeration of lock modes competes with the JPA-defined
5566
* {@link LockModeType}, but offers additional options, including
5667
* {@link #UPGRADE_NOWAIT} and {@link #UPGRADE_SKIPLOCKED}.

0 commit comments

Comments
 (0)