As I was about to post the question I realised the answer is to use a Hibernate DetachedCriteria
to contain the THING
restriction subquery. And then to add that into the criteria for THING_CATEGORY
main query.
So the Hibernate code looks like this:
public List<ThingCategory> getRestrictedByCountrySet(List<String> countryCodes)
{
Criterion thingCriterion = Restrictions.in("countryCode", countryCodes);
DetachedCriteria thingSubQuery = DetachedCriteria.forClass(Thing.class)
.add(thingCriterion)
.setProjection(Projections.property("categoryCode");
Criteria thingCategoryCriteria = getHbSession().createCriteria(ThingCategory.class)
.add(Property.forName("code").in(thingSubQuery));
return thingCategoryCriteria.list();
}