title: Eager fetching collections in Hibernate with ScrollableResults
body: <p>I'm trying to use Hibernate to retrieve approximately 100 million rows from a table.  I have a persisted entity Item that contains a collection of Fees inside (another persisted entity).  Given that I <em>will</em> iterate over the result and access the fees for every object, I want to eagerly fetch fees to avoid the n+1 problem.</p>
  
  <p>I should also mention that I want to join it to another table called Provider (one-to-one mapping but no foreign key).  I tried:</p>
  
  <pre><code>String query = "select new " + Order.class.getName() 
             + "(i, p) from Item i left join fetch i.fees f, Provider p where "
             + "p.factoryId=i.factoryId and p.factoryRef=i.factoryRef";
  
  return session.createQuery(query).scroll();
  </code></pre>
  
  <p>My Order class contains a Provider field and an Item field.  I get this error:</p>
  
  <blockquote>
    <p>Caused by: org.hibernate.QueryException: query specified join
    fetching, but the owner of the fetched association was not present in
    the select list</p>
  </blockquote>
  
  <p>I would like to end up with a scrollable list of Order which contain Item (with the fees eagerly fetched) and Provider.</p>