With JPA, we can use manually OPTIMISTIC or PESSIMISTIC locking to handle entity changes in transactions.
OPTIMISTIC
PESSIMISTIC
I wonder how JPA handles locking
In the specification persistence_2.0, page 89:
If a versioned object is otherwise updated or removed, then the implementation must ensure that the requirements of LockModeType.OPTIMISTIC_FORCE_INCREMENT are met, even if no explicit call to EntityManager.lock was made.