How can I use a subquery in Criteria?
I have a object Country and a object CountryName.
Country has an one-to-many relation to CountryName.
In SQL I would use:
Code:
SELECT * FROM countries WHERE id IN (SELECT country FROM countryNames WHERE ...) AND ...
The question is how to do this part: id IN (subquery)
At the moment I have this code:
Code:
DetachedCriteria countryNames = DetachedCriteria.forClass(CountryName.class);
countryNames.setProjection(Property.forName("country"));
countryNames.add(Restrictions.eq("name", countryName));// countryName is a string
Country country = (Country) session.createCriteria(Country.class).add(Subqueries.in(, countryNames)).list().get(0);