code: public static <T> Long count(EntityManager em, CriteriaQuery<T> criteria) {
  
          return em.createQuery(countCriteria(em, criteria)).getSingleResult();
      }
docs: Result count from a CriteriaQuery
  
  @param em       Entity Manager
  @param criteria Criteria Query to count results
  @return row count