It a Persistence application locks entity x with a pessimistic lock, which statement is true?

It a Persistence application locks entity x with a pessimistic lock, which statement is true?

It a Persistence application locks entity x with a pessimistic lock, which statement is true?

A.
Persistence provider can defer obtaining the lock until the next synchronization of an entity to the database.

B.
A Persistenceprovider will obtain the lock when the entity is refreshed from the database.

C.
A Persistence provider is not required to support the LockModeType. PESSIMISTIC_WRITE locking type.

D.
If a lock cannot be obtained, the Persistence provider must throw an exception.

Explanation:
http://www.eclipse.org/eclipselink/api/2.0/javax/persistence/LockModeType.html
Ref: When the lock cannot be obtained, and the database locking failure results in transaction-level rollback, the provider must throw the PessimisticLockException and ensure that the JTA transaction or EntityTransaction has been marked for rollback.



Leave a Reply 1

Your email address will not be published. Required fields are marked *


Tommy_Croatia_ZGB

Tommy_Croatia_ZGB

Correct answer is D.

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.