0

I have put @Lock(LockModeType.PESSIMISTIC_WRITE) on a query and working on it in service layer with @Transactionsal annotation. The lock is acquired successfully. But for some cases, the transaction could not be happened. And this lock takes time to be released. My concern is how can I release the lock immediately ?

idrak_07
  • 19
  • 5

1 Answers1

1

You can explicitly unlock by

entityManager.lock(entityObject, LockModeType.NONE);

  • That would be implementation specific as the JPA spec says nothing about unlocking locks - there are other lock types, and all this does in the spec is get (or check) a lock in the database. Optimistic locking for instances verifies and increments the version - only a rollback 'unlocks' or undoes the version change. – Chris Jun 13 '22 at 15:25
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 15 '22 at 01:13