How to do a distinct count in JPA critera API?

后端 未结 4 1576
盖世英雄少女心
盖世英雄少女心 2021-02-13 10:14

I would like to do this but with the criteria API instead:

select count(distinct e) from Event e, IN(e.userAccessPermissions) p where p.principal = :principal an         


        
4条回答
  •  萌比男神i
    2021-02-13 10:31

    You can use countDistinct on CriteriaBuilder

    criteriaQuery.select(criteriaBuilder.countDistinct(entityRoot))
    

提交回复
热议问题