是的,您需要单独的查询来获取总结果数。
Query aCountQuery = session.createQuery("select count(s.id) from Student s
where s.enquiryStatus != :enquiryStatus");
aCountQuery.setParameter("enquiryStatus", ENQUIRY.JOINED);
Long resultCount = (Long)aCountQuery.uniqueResult();
或者
Criteria criteria=session.createCriteria(Student.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.add(Restrictions.ne("enquiryStatus", ENQUIRY.JOINED));
criteria.setProjection(Projections.rowCount())
Long resultCount = (Long)criteria.uniqueResult();
更新
现在,您可以使用相同的条件来获取具有分页和结果计数的结果
Criteria criteria=session.createCriteria(Student.class);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
criteria.add(Restrictions.ne("enquiryStatus", ENQUIRY.JOINED));
criteria.setMaxResults(10);
criteria.setFirstResult((paginate.getStartIndex()-1)*10);
List<Student> students = criteria.list();
criteria.setProjection(null);
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
Long resultCount = (Long)criteria.uniqueResult();