code: public Long count(Criteria<T, T> criteria) {
          SingularAttribute<? super T, PK> id = getEntityManager().getMetamodel().entity(entityClass).getId(entityKey);
          return criteria.select(Long.class, countDistinct(id))
                  .getSingleResult();
      }
docs: Count using a pre populated criteria
  
  @param criteria
  @return