diff --git a/hibernate-core/src/main/java/org/hibernate/Session.java b/hibernate-core/src/main/java/org/hibernate/Session.java index 96219e55e6..67ed6b5a73 100644 --- a/hibernate-core/src/main/java/org/hibernate/Session.java +++ b/hibernate-core/src/main/java/org/hibernate/Session.java @@ -11,6 +11,7 @@ import java.util.function.Consumer; import jakarta.persistence.CacheRetrieveMode; import jakarta.persistence.CacheStoreMode; +import jakarta.persistence.LockModeType; import jakarta.persistence.PessimisticLockScope; import org.hibernate.graph.RootGraph; import org.hibernate.jdbc.Work; @@ -75,6 +76,9 @@ import jakarta.persistence.criteria.CriteriaUpdate; * detached instance to the persistent state are now deprecated, and clients should now * migrate to the use of {@code merge()}. *
+ * The persistent state of a managed entity may be refreshed from the database, discarding + * all modifications to the object held in memory, by calling {@link #refresh(Object)}. + *
* From {@linkplain FlushMode time to time}, a {@linkplain #flush() flush operation} is * triggered, and the session synchronizes state held in memory with persistent state * held in the database by executing SQL {@code insert}, {@code update}, and {@code delete} @@ -82,6 +86,20 @@ import jakarta.persistence.criteria.CriteriaUpdate; * of the {@code Session} interface. If synchronous execution of SQL is desired, the * {@link StatelessSession} allows this. *
+ * Each managed instance has an associated {@link LockMode}. By default, the session + * obtains only {@link LockMode#READ} on an entity instance it reads from the database + * and {@link LockMode#WRITE} on an entity instance it writes to the database. This + * behavior is appropriate for programs which use optimistic locking. + *
* A persistence context holds hard references to all its entities and prevents them * from being garbage collected. Therefore, a {@code Session} is a short-lived object, * and must be discarded as soon as a logical transaction ends. In extreme cases,