title: Using not-found attribute of one-to-many mapping of hibernate
body: <p>As per Hibernate docs for <code>one-to-many</code> xml mapping tag there is an attribute called as <code>not-found</code></p>
  
  <p><a href="http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/collections.html#collections-onetomany" rel="nofollow">http://docs.jboss.org/hibernate/orm/3.3/reference/en-US/html/collections.html#collections-onetomany</a></p>
  
  <p>The Doc says:</p>
  
  <blockquote>
    <p>not-found (optional - defaults to exception): specifies how cached
    identifiers that reference missing rows will be handled. ignore will
    treat a missing row as a null association.</p>
  </blockquote>
  
  <p>What is the use of this attribute? I tried to create a mapping between Product and Parts with Product having a set of Parts with below mapping details:</p>
  
  <pre><code>&lt;set name="parts" cascade="all"&gt;
      &lt;key column="productSerialNumber" not-null="true" /&gt;
      &lt;one-to-many class="Part" not-found="ignore"/&gt;
  &lt;/set&gt;
  </code></pre>
  
  <p>Then I wrote my Java code as:</p>
  
  <pre><code>public static void main(String[] args) {
          Session session = HibernateUtil.getSessionFactory().getCurrentSession();
          session.beginTransaction();
          Product prod = (Product) session.get(Product.class, 1);
  
          session.getTransaction().commit();
          System.out.println(prod);
          HibernateUtil.getSessionFactory().close();
      }
  </code></pre>
  
  <p>I was expecting null for my set which has Parts as I configured in my mapping file as <code>not-found="ignore"</code>. But I got the regular exception - <code>org.hibernate.LazyInitializationException</code></p>
  
  <p>Please help me in understanding what is the use of this attribute? What are cached identifiers here?</p>