lock(entity, lockMode, properties) - JPA EntityManager's method
If a pessimistic lock mode type is specified and the entity contains a version attribute, the persistence provider must also perform optimistic version checks when obtaining the database lock. If these checks fail, the
OptimisticLockException will be thrown.
If the lock mode type is pessimistic and the entity instance is found but cannot be locked:
PessimisticLockExceptionwill be thrown if the database locking failure causes transaction-level rollback
LockTimeoutExceptionwill be thrown if the database locking failure causes only statement-level rollback
If a vendor-specific property or hint is not recognized, it is silently ignored.
Portable applications should not rely on the standard timeout hint. Depending on the database in use and the locking mechanisms used by the provider, the hint may or may not be observed.
entity- entity instance
lockMode- lock mode
properties- standard and vendor-specific properties and hints
IllegalArgumentException- if the instance is not an entity or is a detached entity
TransactionRequiredException- if there is no transaction
EntityNotFoundException- if the entity does not exist in the database when pessimistic locking is performed
OptimisticLockException- if the optimistic version check fails
PessimisticLockException- if pessimistic locking fails and the transaction is rolled back
LockTimeoutException- if pessimistic locking fails and only the statement is rolled back
PersistenceException- if an unsupported lock call is made
- JPA 2.0