Skip to content

Commit aae9b1e

Browse files
committed
talk about lock() and refresh() in javadoc preamble for Session
Signed-off-by: Gavin King <gavin@hibernate.org>
1 parent 38c56ac commit aae9b1e

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import jakarta.persistence.CacheRetrieveMode;
1313
import jakarta.persistence.CacheStoreMode;
14+
import jakarta.persistence.LockModeType;
1415
import jakarta.persistence.PessimisticLockScope;
1516
import org.hibernate.graph.RootGraph;
1617
import org.hibernate.jdbc.Work;
@@ -75,13 +76,30 @@
7576
* detached instance to the persistent state are now deprecated, and clients should now
7677
* migrate to the use of {@code merge()}.
7778
* <p>
79+
* The persistent state of a managed entity may be refreshed from the database, discarding
80+
* all modifications to the object held in memory, by calling {@link #refresh(Object)}.
81+
* <p>
7882
* From {@linkplain FlushMode time to time}, a {@linkplain #flush() flush operation} is
7983
* triggered, and the session synchronizes state held in memory with persistent state
8084
* held in the database by executing SQL {@code insert}, {@code update}, and {@code delete}
8185
* statements. Note that SQL statements are often not executed synchronously by the methods
8286
* of the {@code Session} interface. If synchronous execution of SQL is desired, the
8387
* {@link StatelessSession} allows this.
8488
* <p>
89+
* Each managed instance has an associated {@link LockMode}. By default, the session
90+
* obtains only {@link LockMode#READ} on an entity instance it reads from the database
91+
* and {@link LockMode#WRITE} on an entity instance it writes to the database. This
92+
* behavior is appropriate for programs which use optimistic locking.
93+
* <ul>
94+
* <li>A different lock level may be obtained by explicitly specifying the mode using
95+
* {@link #get(Class, Object, LockMode)}, {@link #find(Class, Object, LockModeType)},
96+
* {@link #refresh(Object, LockMode)}, {@link #refresh(Object, LockModeType)}, or
97+
* {@link org.hibernate.query.SelectionQuery#setLockMode(LockModeType)}.
98+
* <li>The lock level of a managed instance already held by the session may be upgraded
99+
* to a more restrictive lock level by calling {@link #lock(Object, LockMode)} or
100+
* {@link #lock(Object, LockModeType)}.
101+
* </ul>
102+
* <p>
85103
* A persistence context holds hard references to all its entities and prevents them
86104
* from being garbage collected. Therefore, a {@code Session} is a short-lived object,
87105
* and must be discarded as soon as a logical transaction ends. In extreme cases,

0 commit comments

Comments
 (0)