Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do a distinct count in JPA critera API?

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 and p.permission in (:permissions)

Any ideas?

like image 855
Piotr Avatar asked Jun 01 '11 07:06

Piotr


1 Answers

You can use countDistinct on CriteriaBuilder

criteriaQuery.select(criteriaBuilder.countDistinct(entityRoot))
like image 146
Jakub Kahovec Avatar answered Nov 02 '22 18:11

Jakub Kahovec