Having realized that your actual entity mappings (and this, of course, is completely untested), are probably solved by something similar to
Session hibernateSession = ... (however you get it). DetachedCriteria d = DetachedCriteria.forClass(Foo.class) .add(Restrictions.eq("column1", 11)) .setProjection(Projections.property("column2")); Criteria criteria = hibernateSession.createCriteria(Foo.class) .add(Restrictions.eq("column1", 8)) .add(Subqueries.propertyNotIn("column2", d)); List<Foo> result = criteria.list();
This will almost certainly require adjustment, since "column1" and "column2" are sql field names, and what you need in these places are java properties.
source share