In JPA 2, using a CriteriaQuery, how to count results

前端 未结 7 1133
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-28 19:28

I am rather new to JPA 2 and it\'s CriteriaBuilder / CriteriaQuery API:

CriteriaQuery javadoc

CriteriaQuery in the Java EE 6 tutorial

I would like to

相关标签:
7条回答
  • 2020-11-28 20:13

    You can also use Projections:

    ProjectionList projection = Projections.projectionList();
    projection.add(Projections.rowCount());
    criteria.setProjection(projection);
    
    Long totalRows = (Long) criteria.list().get(0);
    
    0 讨论(0)
提交回复
热议问题