title: How to do optimistic locking in hibernate
body: <p>I am completely new to Hibernate and Spring and in my attempt to learn Spring, Hibernate, Maven etc I only know how to run a hello world example using all of the three.  With my basic understanding I have been assigned a task for performing optimistic locking. As far as I have googled it I can only see it is not very difficult all I need is to add a version tag in my xml and integer variable version in my mapped class.. Like this...</p>
  
  <pre><code>public class MyClass {
  ...
  private int version;
  ...
  }
  </code></pre>
  
  <p>my xml should be like this</p>
  
  <pre><code>&lt;class name="MyClass"&gt;
  &lt;id ...&gt;
  &lt;version name="version" column="VERSION" access="field"&gt;
  ...
  &lt;/class&gt;
  </code></pre>
  
  <p>And hibernate will automatically take care of versioning when second user saves, hibernate finds this user is working on the stale data and throws StaleObjectException.</p>
  
  <p>Just wanted to confirm my understanding, thanks in advance.</p>
  
  <p>It will be really helpful if some one can point me to a hello world example for this.</p>
  
  <p>I would also like to mention that I am trying to implement "last commit wins" scenerio</p>