title: How to unlock one entity under JPA
body: <p>all.</p>
  
  <p>I was writting a program using pure JPA , whose provider was hibernate, and the underlying database was Azure SQL DB. This program will run under a distributed environment, many copy of it will be running on different servers.</p>
  
  <p>I need go some procedure like that (for ex-):<br>
    1, lock a specified student entity, <br>
    2, check the status of clas entity, if the status was 1,then continue, else, try to lock this class entity , untile get the lock of this class <br>
    3, check the status of the status  ( maybe modified by other thread from the another server due to distributed environment), if still not 1, then do something, modified the status to 1,<br>
    4,  unlock  this class entity <br>
    5, do other things ( still hold the lock over present student entity)<br></p>
  
  <p>i get lock by the following code seg:</p>
  
  <pre><code>    Map&lt;String,Object&gt; map = new HashMap&lt;String, Object&gt;();
      map.put("javax.persistence.lock.timeout", 0);
      return this.getEntityManager().find( cls, id,  LockModeType.PESSIMISTIC_WRITE,map);
  </code></pre>
  
  <p>but, i dont know how to realease the lock at step 4,
  Are there any method to just realse the lock over a entity ,and remained other locks?</p>
  
  <p>Thanks a lot, any advice will be appropriated. </p>