Java EE 7 Application Developer — Question 28
A Persistence application locks entity x with a LockModeType.PESSIMISTIC_READ lock type. Which statement is true?
Answer options
- A. LockModeType.PESSIMISTIC_READ is the synonym of LockModeType.READ
- B. This operation will force serialization among transactions attempting to read the entity data.
- C. This operation will result in a TransactionRolledbackException if the lock cannot be obtained.
- D. If the application updates the entity later, and the changes are flushed to the database, the lock will be converted to an exclusive look.
Correct answer: B
Explanation
The correct answer is B because a PESSIMISTIC_READ lock allows other transactions to read the data but prevents them from acquiring a write lock until the current transaction completes, thus enforcing serialization. Option A is incorrect because PESSIMISTIC_READ and READ are not synonymous; they have different implications for locking. Option C is wrong, as a PESSIMISTIC_READ lock typically does not lead to a TransactionRolledbackException if the lock cannot be obtained, but rather just blocks the transaction. Option D is also incorrect because a PESSIMISTIC_READ lock does not automatically become an exclusive lock upon updates.