I have created a Hibernate (3.5) Criteria query:
Criteria criteria = db.getSession().createCriteria(Vendor.class);
criteria.add(Restrictions.isEmpty("models"));
When executed with Criteria.list, Hibernate produces the following SQL (simplified for sake of readability):
SELECT this_.*
FROM VENDOR this_
left outer join MODEL models1_
ON this_.id = models1_.VENDOR_ID
WHERE NOT EXISTS (SELECT 1
FROM MODEL
WHERE this_.id = VENDOR_ID)
What I'd like to do is add a restriction within the "not exists" part so that the SQL query would look like this
SELECT this_.* FROM VENDOR this_
left outer join MODEL models1_
ON this_.id = models1_.VENDOR_ID
WHERE
NOT EXISTS (SELECT 1
FROM MODEL
WHERE this_.id = VENDOR_ID AND DEPRECATED = 0 )
Is that possible using the Hibernate Criteria API and if yes, how? Or is there some other possibility to achieve the same result (but still using Criteria API)?