title: JPA Hibernate fetchSize Query hint Issue
body: <p>I have been using JPA 2.0 with hibernate as the vendor for my web application.  For one of the database queries, I am using the JPA criteria builder API to construct the dynamic queries . I have been able to get it to work as expected.</p>
  
  <p>The query has a fetch join between two tables A &amp; B. A has a OneToMany relationship with B.</p>
  
  <pre><code>Join&lt;A,B&gt; ordLeg = ord.joinSet("bLegs", JoinType.INNER);
  ord.fetch("bLegs",JoinType.INNER);
  </code></pre>
  
  <p>I also have used the setMaxResults to restrict the no. of records returned to the user</p>
  
  <pre><code>typedQuery.setMaxResults(10);
  </code></pre>
  
  <p>FYI, there are around 400 records in the database.</p>
  
  <p>When I see the result of the query in the logs, I see that it loads all the 400 records in the memory. However, it returns only 20 records to the user since Maxresults is set.</p>
  
  <p>When analyzed further, found out that hibernate has hints that can be given to fetch records in batches rather than loading all the 400 records in the memory.</p>
  
  <pre><code>TypedQuery&lt;A&gt; typedQuery = entityManager.createQuery(query);
  typedQuery.setHint("org.hibernate.fetchSize", 5);
  List&lt;A&gt; orderList = (List&lt;A&gt;) typedQuery.getResultList();
  </code></pre>
  
  <p>But it does not seem to take the hint at all. I am still seeing that it loads all 400 records in the memory and no batch fetching is done. I am expecting it to fetch the 10 (maxResults ) records in 2 batches of 5.  Am i missing something ?\</p>
  
  <p>It will be a severe performance hit if there are more than 1000 records in the DB  for the specified query.</p>
  
  <p>I even tried setting the following property in the persistence.xml level but in vain.</p>
  
  <pre><code>&lt;properties&gt;
  &lt;property name="hibernate.jdbc.batch_size" value="5"/&gt;  
  &lt;property name="hibernate.jdbc.fetch_size" value="5"&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p>Can you please help me out in the right direction ?</p>
  
  <p>Hibernate Version:  I have tried 3.6.4.Final, 4.0.0.Final &amp;  4.2.1.Final</p>
  
  <p>Appreciate your help.</p>
  
  <p>Thanks,
  Santhosh</p>