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

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.