Issue
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 ?
Solution
You can explicitly unlock by
entityManager.lock(entityObject, LockModeType.NONE);
Answered By - Ali Naser Khan
Answer Checked By - David Marino (JavaFixing Volunteer)