|
11 | 11 |
|
12 | 12 | import jakarta.persistence.CacheRetrieveMode; |
13 | 13 | import jakarta.persistence.CacheStoreMode; |
| 14 | +import jakarta.persistence.LockModeType; |
14 | 15 | import jakarta.persistence.PessimisticLockScope; |
15 | 16 | import org.hibernate.graph.RootGraph; |
16 | 17 | import org.hibernate.jdbc.Work; |
|
75 | 76 | * detached instance to the persistent state are now deprecated, and clients should now |
76 | 77 | * migrate to the use of {@code merge()}. |
77 | 78 | * <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> |
78 | 82 | * From {@linkplain FlushMode time to time}, a {@linkplain #flush() flush operation} is |
79 | 83 | * triggered, and the session synchronizes state held in memory with persistent state |
80 | 84 | * held in the database by executing SQL {@code insert}, {@code update}, and {@code delete} |
81 | 85 | * statements. Note that SQL statements are often not executed synchronously by the methods |
82 | 86 | * of the {@code Session} interface. If synchronous execution of SQL is desired, the |
83 | 87 | * {@link StatelessSession} allows this. |
84 | 88 | * <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> |
85 | 103 | * A persistence context holds hard references to all its entities and prevents them |
86 | 104 | * from being garbage collected. Therefore, a {@code Session} is a short-lived object, |
87 | 105 | * and must be discarded as soon as a logical transaction ends. In extreme cases, |
|
0 commit comments