mysql - Physical lock on DB rows obtained from a JPA PESSIMISTIC lock -
according jpa 2.1 specification...
the lock modes
pessimistic_read,pessimistic_write, ,pessimistic_force_incrementused obtain long-term database locks.
i assume pessimistic lock trigger select ... update sql on database, no matter lock-mode used. 3 questions on that:
- is assumption correct or there exceptions rule, if correct?
- given
select ... updatelocked rows. locked rows cannot updated other transaction except transaction locked it? - the lock can released performing commit or rollback on transaction. happens lock if application (and transaction locked rows) terminates without doing commit or rollback on transaction?
for question 1 , 2, assumptions correct:
yes - pessimistic lock uses
select ... update, databases , jpa implementations support type of lock. in case there no difference between read , write block, , jpa specification allows long both behave write locks.yes - locked rows cannot modified other transaction. in case of write lock (and time read lock - se answer 1), locked rows cannot read until lock released. note other unlocked rows in same table free read , modified.
to answer question 3:
- yes - locks release in case of commit or rollback. however, rollback happens automatically when error happens, or connection dropped, or transaction takes long. so, when application dies, rollback triggered immediately. if not, rolled after timeout (usually 5 minutes).
Comments
Post a Comment