According to the JPA 2.1 specification...
The lock modes
PESSIMISTIC_READ
,PESSIMISTIC_WRITE
, andPESSIMISTIC_FORCE_INCREMENT
are used to immediately obtain long-term database locks.
I assume a pessimistic lock will always trigger a SELECT ... FOR UPDATE
SQL on the database, no matter what lock-mode is used. Now three questions on that:
- Is the assumption correct or are there exceptions from this rule, if correct?
- Given a
SELECT ... FOR UPDATE
locked the rows. Locked rows cannot be updated by any other transaction except the transaction which locked it? - The lock can be released by performing a commit or rollback on the transaction. What happens with the lock if the application (and the transaction which locked the rows) suddenly terminates without doing a commit or a rollback on the transaction?