title: Hibernate LockModes/LockOptions
body: <p>I am going through Hibernate Documentation an came across the <code>LockModes</code>. Are these same as <code>Isolation levels</code> that we use for database? How are they different from <code>Isolation levels</code>?</p>
  
  <p>I am trying a simple example and observed that the hibernate is hitting the database when I use session.load() method itself instead of hitting the DB when I call some methods on the loaded object.</p>
  
  <pre><code>session.beginTransaction(); //Line 1
  DomesticCat d1 = (DomesticCat)session.load(DomesticCat.class, 1L,LockOptions.UPGRADE); //Line 2
  d1.meow(); //Line 3
  session.getTransaction().commit(); //Line 4
  </code></pre>
  
  <p>I observed that hibernate hits the database at line 2 itself, please tell me why it happens like that? If I remove the LockOptions parameter then the DB hit is made on <code>Line 3</code> instead of <code>Line 2</code></p>
  
  <p>The <a href="http://docs.jboss.org/hibernate/annotations/3.5/api/org/hibernate/LockOptions.html#READ" rel="noreferrer">API for LockOptions</a> gives very little details on what they are:</p>
  
  <blockquote>
    <p>READ represents LockMode.READ (timeout + scope do not apply)</p>
  </blockquote>
  
  <p>What does it mean that <code>timeout + scope do not apply</code>?</p>
  
  <blockquote>
    <p>UPGRADE represents LockMode.UPGRADE (will wait forever for lock and
    scope of false meaning only entity is locked)</p>
  </blockquote>
  
  <p>When we should use UPGRADE? what it means that <code>scope of false meaning only entity is locked</code>?</p>
  
  <p>May be these are basic questions for experienced guys, please help me in understanding the concept here.</p>
  
  <p>Thanks for looking my post.</p>