学生选课系统小案例:https://blog.csdn.net/zc_ad/article/details/83578487
Spring Data JPA 之 for update
Entity Locking
In the area of concurrency control, the JPA specification supports optimistic and pessimistic locking.
public void lock(Object entity, LockModeType mode);
This method locks the given entity using the named mode. The javax.persistence.LockModeType
enum defines eight modes:
-
OPTIMISTIC
: Optimistic locking. -
OPTIMISTIC_FORCE_INCREMENT
: Optimistic locking. When a transaction is committed, the entity's version column will be incremented