public static < T > CriteriaQuery < Long > countCriteria ( EntityManager em , CriteriaQuery < T > criteria ) { CriteriaBuilder builder = em . getCriteriaBuilder ( ) ; CriteriaQuery < Long > countCriteria = builder . createQuery ( Long . class ) ; copyCriteriaNoSelection ( criteria , countCriteria ) ; countCriteria . select ( builder . count ( findRoot ( countCriteria , criteria . getResultType ( ) ) ) ) ; return countCriteria ; }
Create a row count CriteriaQuery from a CriteriaQuery