title: what is the purpose of session.lock method in Hibernate
body: <p>I am going through <a href="http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/Session.html#lock" rel="noreferrer">lock method</a> of hibernate. I did not get what we are trying to achieve through this method. </p>
  
  <pre><code> p1  = (Person)session. get(Person.class,1);// person name is scott here
  // here peson name got update to henry by anothet thread
  session. lock(person, LockMode.READ) line 3
  // still name is henry too
  </code></pre>
  
  <p>I tried  above code snippet but it did not read the person from database at line 3.
  Documentation says that This may be used to perform a version check.</p>
  
  <p>Not sure how does it check version and helps the developer in any scenario?</p>
  
  <p>Similarly not sure what <code>session.lock(person, LockMode.None)</code> will achieve. Documentation says <code>LockMode.NONE</code> is used to  to simply re-associate a transient instance with a session.</p>
  
  <p>Not sure what does it mean by reassociating a transient instance with session. A brief scenario will be a great help?</p>