JPA Method
in javax.persistence.EntityManager

void refresh(
  Object entity, 
  LockModeType lockMode
)


Refresh the state of the instance from the database, overwriting changes made to the entity, if any, and lock it with respect to given lock mode type.

If the lock mode type is pessimistic and the entity instance is found but cannot be locked:

  • the PessimisticLockException will be thrown if the database locking failure causes transaction-level rollback
  • the LockTimeoutException will be thrown if the database locking failure causes only statement-level rollback.
Parameters:
entity - entity instance
lockMode - lock mode
Throws:
IllegalArgumentException - if the instance is not an entity or the entity is not managed
TransactionRequiredException - if invoked on a container-managed entity manager of type PersistenceContextType.TRANSACTION when there is no transaction; if invoked on an extended entity manager when there is no transaction and a lock mode other than NONE has been specified; or if invoked on an extended entity manager that has not been joined to the current transaction and a lock mode other than NONE has been specified
EntityNotFoundException - if the entity no longer exists in the database
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
Since:
JPA 2.0