title: JPA count(*) using CriteriaBuilder. How to use CriteriaBuilder to retrive the count(*) column
body: <p>I have a question about CriteriaBuilder API:</p>
  
  <p>I would like to count the results of a column with returning back the result of that counting and the list of the distinct values of that column.</p>
  
  <pre class="lang-none prettyprint-override"><code>|      Table_fruit       |     count(Table_fruit)    |
  |------------------------|---------------------------|
  |          apple         |         (5)               |
  |          orange        |         (20)              |
  |          banana        |         (400)             |     
  </code></pre>
  
  <p>So I want to make a query that will do this SQL statement: </p>
  
  <pre><code>select distinct COLUMN_NAME_1, count(COLUMN_NAME_1)
  from TABLE_NAME
  where COLUMN_NAME_2= 'value'
  group by COLUMN_NAME_1;
  </code></pre>
  
  <pre class="lang-java prettyprint-override"><code>    CriteriaBuilder cb = getCriteriaBuilder();
      CriteriaQuery&lt;Fruit&gt; cq = cb.createQuery(Fruit.class);
  
      Root&lt;TABLE_NAME&gt; root = cq.from(Fruit.class);
  
      List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
      predicates.add(cb.equal(root.get("COLUMN_NAME_2"), value));
      cq.where(predicates.toArray(new Predicate[predicates.size()]));
  
      // how to select the COUNT(*) from the table here? 
  
  
      cq.select(root.get("COLUMN_NAME_1")).distinct(true);
  
      cq.groupBy(root.get("COLUMN_NAME_1"));
  </code></pre>
  
  <p>So my question is: how to retrieve the two values from the query in Java</p>