Search code examples
sqlhibernatecriteriahibernate-criteriadetachedcriteria

Subselect, Group by and Having Count with criteria in hibernate


I have a query like this:

SELECT ap.person_id FROM 
     (SELECT distinct ac.person_id person_id,ac.user_id 
      FROM zrm_actor ac WHERE ac.deleted != 1) ap 
WHERE person_id IS NOT NULL 
GROUP BY person_id HAVING COUNT(*) > 1;

How can I write this query with criteria?


Solution

  • There is no way to create sub-criteria from a sub-select that it's not match an entity.

    SELECT distinct ac.person_id person_id,ac.user_id 
     FROM zrm_actor ac WHERE ac.deleted != 1
    

    The above query don't match with any entity, so there is no way to create sub-criteria from it.