title: JPA criteria api, count number of grouped rows
body: <p>I need to implement paging on a query that looks like this:</p>
  
  <p><code>select a,b,c, sum(b) from t group by a,b,c</code></p>
  
  <p>in order to do this I need to count the number of rows. The easiest way to do it in SQL is with subquery on from clause:</p>
  
  <p><code>select count(*) from select a,b,c sum(d) from t group by a,b,c</code></p>
  
  <p>How to do it in criteria api? As far as I can see JPA does not support subquery in from clause (neither does Hibernate). Using native query is not an option because I have quite complex dynamic where condition, and getting the whole list just to fetch the size seems just wrong.</p>