How to remove Session lock in Hibernate
<p>I am using older version of Hibernate in my application. I used <code>session.lock(object,LOCKMODE.UPGRADE)</code> in my code to avoid stalestate exception. I am able to resolve the issue, but after some DB transactions, application is hanged out(my guess is DeadLock is happening). My goal is after my transaction is done I want to remove the lock on my object. How can i achieve the same.</p>

<p>The problems what I am facing(StaleStateException) is not because detached objects. It is due to the entity is being modified by other transactions(or threads) , before we persist into   DB. Below is our code flow.</p>

<pre><code>DbRecord record = DAO.getBy(Id);
session.lock(record,LockMode.Upgrade);
// updating some record details and saving again into DB
session.saveOrUpdate(record)
</code></pre>

<p>My goal I want to release lock afte save or update. </p>