How to unlock @Lock(LockModeType.PESSIMISTIC_WRITE) if there is no transaction

1.9k Views Asked by At

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 ?

1

There are 1 best solutions below

2
Ali Naser Khan On BEST ANSWER

You can explicitly unlock by

entityManager.lock(entityObject, LockModeType.NONE);