1Z0-898 · Question #10
Which EntityManager API will lock entity x with a pessimistic lock?
The correct answer is C. em.lock(x, LockModeType.PESSIMISTIC_READ). Setting a Pessimistic Lock An entity object can be locked explicitly by the lock method: em.lock(employee, LockModeType.PESSIMISTIC_WRITE); The first argument is an entity object. The second argument is the requested lock mode. A LockTimeoutException is thrown if the requested…
Question
Which EntityManager API will lock entity x with a pessimistic lock?
Options
- Aem.lock(x, LockModeType.WRITE)
- Bem.lock(x, LockModeType.PESSIMISTIC)
- Cem.lock(x, LockModeType.PESSIMISTIC_READ)
- Dem.lock(x, LockModeType.OPTIMISTIC_FORCE_INCREMENT)
How the community answered
(18 responses)- A6% (1)
- B17% (3)
- C72% (13)
- D6% (1)
Explanation
Setting a Pessimistic Lock An entity object can be locked explicitly by the lock method: em.lock(employee, LockModeType.PESSIMISTIC_WRITE); The first argument is an entity object. The second argument is the requested lock mode. A LockTimeoutException is thrown if the requested pessimistic lock cannot be granted: *A PESSIMISTIC_READ lock request fails if another user (which is represented by another EntityManager instance) currently holds a PESSIMISTIC_WRITE lock on that database object. *A PESSIMISTIC_WRITE lock request fails if another user currently holds either a PESSIMISTIC_WRITE lock or a PESSIMISTIC_READ lock on that database object.
Topics
Community Discussion
No community discussion yet for this question.