title: Hibernate equivalent to EclipseLink's batch query hint?
body: <p>One thing I like about <a href="http://www.eclipse.org/eclipselink/" rel="noreferrer">EclipseLink</a> has this great thing called the <a href="http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#Batch" rel="noreferrer">batch query hint</a>, which I'm yet to find a Hibernate equivalent of.</p>
  
  <p>Basically doing a whole bunch of joins gets messy real quick and you end up querying way more data than you necessarily want (remember that if you join person to 6 addresses the person information is returned 6 times; now keep multiplying that out by extra joins).</p>
  
  <p>Imagine a Person entity with 0:M collections of Address, Email, Phone and OrderHistory.  Joining all that is not good but with the batch method:</p>
  
  <pre><code>List persons = entityManager.createQuery("select p from Person p"
    .setHint(QueryHints.BATCH, "p.address")
    .setHint(QueryHints.BATCH, "p.email")
    .setHint(QueryHints.BATCH, "p.phone")
    .setHint(QueryHints.BATCH, "p.orderHistory")
    .getResultList();
  </code></pre>
  
  <p>This will do a query on the Person table and that's it.  When you first access an address record it will do a <strong>single query</strong> for the <strong>entire</strong> Address table.  If you specified a where clause on the Person table, this same criteria will be used for the Address load too.</p>
  
  <p>So instead of doing 1 query, you do 5.</p>
  
  <p>If you were doing that with joins you <strong>might</strong> get it all in one query but you may very well be loading way more data because of the joins.</p>
  
  <p>Anyway, I've gone looking in the Hibernate docs for an equivalent to this but don't see one.  Is there one?</p>