title: Count of the result of a Hibernate Criteria group by - total grouped records returned
body: <p>I have a Criteria-based query with the following grouping:</p>
  
  <pre><code>Projections.projectionList()
      .add(Property.forName("xyz").group()));
  </code></pre>
  
  <p>The SQL generated is (proprietary, so cleansed):</p>
  
  <pre><code>select this_.XYZ as y0_ from FOO.BAR this_ WHERE [long where clause] 
      group by this_.XYZ
  </code></pre>
  
  <p>Now, conceptually, I want to wrap the query results with a count(*) such that the data never comes back from the database, just the count. Like this:</p>
  
  <pre><code>select count(*) from (
    select this_.XYZ as y0_ from FOO.BAR this_ WHERE [long where clause] 
        group by this_.XYZ
  )
  </code></pre>
  
  <p>There could be thousands of rows that I don't need and I'm interested in high-performance, so I don't want that data coming over the network.</p>
  
  <p>My Criteria-based search has numerous conditions. I cannot realistically rebuild it, so I really need to stick with Criteria.</p>
  
  <p>Adding rowCount or count("xyz") doesn't help, of course, because it just reports 1 for each row.</p>
  
  <p>I'm currently doing this to get the count:</p>
  
  <pre><code>ScrollableResults scroll = criteria.scroll();
  scroll.last();
  int count = scroll.getRowNumber();
  </code></pre>
  
  <p>It works, but it is taking a long time to come back with the count (on Oracle if it matters).</p>
  
  <p>Can I do what I'm proposing?</p>