title: Example using countDistinct in a JPA Criteria API query
body: <p>I'm having trouble figuring out how to represent the following JPQL query:</p>
  
  <pre><code>SELECT count(e) FROM Foo e
  </code></pre>
  
  <p>using Criteria API. What I'm trying is:</p>
  
  <pre><code>CriteriaBuilder cb = em.getCriteriaBuilder();
  CriteriaQuery&lt;Foo&gt; c = cb.createQuery(Foo.class);
  Root&lt;Foo&gt; f = c.from(Foo.class);
  c.select(cb.count(f));
  </code></pre>
  
  <p>but this is not working. I also tried:</p>
  
  <pre><code>c.select(cb.count(f.get("id"));
  </code></pre>
  
  <p>This is for JPA2, Eclipselink.</p>