title: Getting count of objects in a Hibernate Criteria Query to display in JSF
body: <p>I have some Hibernate entities that I want to group by <code>paramType</code> and display the parameter type. Here is the <code>controller.getAnalyticsCount()</code> method:</p>
  
  <pre><code>public List&lt;Analytic&gt; getAnalyticCount() {
      Criteria criteria = currentSession().createCriteria(Analytic.class);
      return criteria.setProjection( Projections.projectionList()
                                         .add( Projections.rowCount())
                                         .add( Projections.groupProperty("paramType")).list();
  }
  </code></pre>
  
  <p>Now, in displaying in JSF, the following works, but prints each objects:</p>
  
  <pre><code>&lt;ui:repeat var="foo" value="#{controller.getAnalyticsCount()}"&gt;
      #{foo}
  &lt;/ui:repeat&gt;
  </code></pre>
  
  <p>How do I print the actual counts? Isn't the other fields of the grouped by object available to me? I have also tried <code>.add( Projections.rowCount(),'counts')</code> and #{foo.counts}`. The <a href="http://docs.jboss.org/hibernate/core/3.3/reference/en/html/querycriteria.html#querycriteria-projection" rel="nofollow">documentation</a> seems to be very light in this respect.</p>
  
  <p>PS: Actually, the return type is possibly the reason, but what exactly is the return type in this case, it is no longer of type <code>List&lt;Analytic&gt;</code> I guess.</p>