title: Hibernate filtered collection
body: <p>I'm searching for a solution (if exist) on my need about an hibernate criteria.</p>
  
  <p>I have 
  <strong>ClassA</strong> which have a set of <strong>ClassB</strong> which have a set of <strong>ClassC</strong>.
  ClassC have 5 boolean properties calculated by 5 formulas.</p>
  
  <p>What i need is load every class A with only the ClassB that have at least one ClassC with one property true.</p>
  
  <p>for example:</p>
  
  <ul>
  <li><strong>A1</strong>
  <ul>
  <li><strong>B1</strong>
  <ul>
  <li><strong>C1</strong> (1,0,0,0,0)</li>
  <li>C2 (0,0,0,0,0)</li>
  </ul></li>
  <li>B2
  <ul>
  <li>C3 (0,0,0,0,0)</li>
  </ul></li>
  <li><strong>B3</strong>
  <ul>
  <li>C4 (0,0,0,0,0)</li>
  <li><strong>C5</strong> (0,0,1,0,0)</li>
  <li>C6 (0,0,0,0,0)</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>I want to get by Hibernate only the bold signed object, but hibernate will return everything is inside A1 (correctly!!!). </p>
  
  <p>There is a way to tell hibernate to not load everything?</p>
  
  <p>This is what I do</p>
  
  <pre><code>Criteria c = session.createCriteria(ClassA.class, "a");
  
  c.createAlias("a.classBs", "b").setFetchMode("b", FetchMode.SELECT);
  c.createAlias("b.classCs", "c").setFetchMode("c", FetchMode.SELECT);
  
  Disjunction or = Restrictions.disjunction();
  or.add(Restrictions.eq("c.propOne", Boolean.TRUE));
  or.add(Restrictions.eq("c.propTwo", Boolean.TRUE));
  or.add(Restrictions.eq("c.propThree", Boolean.TRUE));
  or.add(Restrictions.eq("c.propFour", Boolean.TRUE));
  or.add(Restrictions.eq("c.propFive", Boolean.TRUE));
  c.add(or);  
  
  ret = (List&lt;ClassA&gt;) c .list();
  </code></pre>
  
  <p>P.S. I can't use filter into set mapping because boolean property formulas are too long for manteinance</p>