title: Fetch multiple onetoMany relationships Hibernate JPA
body: <p>I am using Hibernate JPA 1.0.</p>
  
  <p>I have the following type of model and I consider manyToOne and oneToOne relationships "eagerly" fetched and oneToMany "lazily" fetched.</p>
  
  <p>I want to fetch Entity A and all its associations where a.id=?</p>
  
  <ul>
  <li>A oneToMany B 
  
  <ul>
  <li>B oneToOne C
  
  <ul>
  <li>C  oneToMany D</li>
  </ul></li>
  <li>B oneToOne E
  
  <ul>
  <li>E  oneToMany D</li>
  </ul></li>
  <li>B oneToOne F
  
  <ul>
  <li>F  oneToMany D</li>
  </ul></li>
  </ul></li>
  </ul>
  
  <p>Is it possible to load this entity in a single query?
  Or in a subset of queries baring in mind the "n+1 selects problem"!</p>
  
  <p>So far my solution to loading all of A associations was to perform the following:</p>
  
  <p>"Select DISTINCT a from A a JOIN FETCH a.bs WHERE a.id=:aID"</p>
  
  <p>And then iterate using code in order to fetch all other associations.</p>
  
  <p>Collection B bs = A.getBs();</p>
  
  <pre><code>         for (final B b : bs) {
           b.getCs().getDs().size();
           b.getEs().getDs().size();
           b.getFs().getDs().size();
           }
  </code></pre>
  
  <p>Obviously there must be a better way of doing this.</p>