A named query that sets an exclusive pessimistic on the entities returned by the query by setting the NamedQuery lockMode element to LockModeType.PESSIMISTIC_FORCE_INCREMENT.
The application starts transaction and executes the query.
Which of the following statements is correct about the entities returned by the query?
A.
Only the current transition may modify or delete the entity instances.
B.
The current transaction may NOT modify or delete the entity instances.
C.
Other concurrent transactions may modify or delete the entity instances.
D.
Other concurrent transactions may modify but MAY NOT delete the entity instances.
current answer A
A
A
A
A
The lock modes LockModeType.PESSIMISTIC_READ, LockModeType.PESSIMISTIC_WRITE, and LockModeType.PESSIMISTIC_FORCE_INCREMENT are used to immediately obtain long-term database locks.
The semantics of requesting locks of type LockModeType.PESSIMISTIC_READ, LockModeType.PESSIMISTIC_WRITE, and LockModeType.PESSIMISTIC_FORCE_INCREMENT are the following.
If transaction T1 calls for a lock of type LockModeType.PESSIMISTIC_READ or LockModeType.PESSIMISTIC_WRITE on an object, the entity manager must ensure that neither of the following phenomena can occur:
• P1 (Dirty read): Transaction T1 modifies a row. Another transaction T2 then reads that row and obtains the modified value, before T1 has committed or rolled back.
• P2 (Non-repeatable read): Transaction T1 reads a row. Another transaction T2 then modifies or deletes that row, before T1 has committed or rolled back.
Correct answer is A.
The general thinking is that if you are requesting a “force/increment” lock you are (1) trying to make sure the entity is not currently in the process of being updated by another transaction and (2) that future transactions will not be able to update it until your transaction is done.