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
Like this?
Criteria crit = session.createCriteria(Event.class): crit.createAlias("userAccessPermissions", "p"); crit.add(Restrictions.eq("p.principal", principal); crit.add(Restrictions.in("p.permission", permissions); crit.setProjection(Projections.countDistinct("id"));