title: Hibernate - Why shouldn't we use FETCH JOIN with scroll()?
body: <p>I'm reading the Hibernate Documentation (version 5.1), and I'm falling on this sentence :</p>
  
  <blockquote>
    <p>Fetch joins should not be used in paged queries (e.g. setFirstResult()
    or setMaxResults()), <strong>nor should they be used with the scroll() or</strong>
    iterate() features.</p>
  </blockquote>
  
  <p>(<a href="http://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#hql-explicit-join" rel="nofollow noreferrer">http://docs.jboss.org/hibernate/orm/5.1/userguide/html_single/Hibernate_User_Guide.html#hql-explicit-join</a>)</p>
  
  <p>I've recently work on a project with a big database (2To) and for many batch treatments we doesn't have any other solution than to use <code>FETCH JOIN</code> with the <code>scroll()</code> method (or we have to leave Hibernate and go back to full SQL query).</p>
  
  <p>I understand that paged queries can't garanty that we have a complete result (while fetching a collection for example).</p>
  
  <p>But when using scroll() (which rely on databases cursors if I'm not making a mistake), if we sort the result by the root entites Ids, I can't see a reason why Hibernate can't garantie the result's coherence and completeness.</p>
  
  <p>What is the reason of that restriction ?</p>
  
  <p>What is the risk for the data fetched ?</p>
  
  <p>Is there a way to prevent it ? (like sorting by ids root entities ?)</p>