I'm using Hibernate 3.0 with Oracle and trying to replicate the following HQL with Criteria:
Code:
from License license
where license.server.configuration.product.id = ?
and license.user.country.id = ?
I've been trying things like this:
Code:
Criteria crit = session.createCriteria(License.class);
crit = crit.createCriteria("server").createCriteria("configuration").add(
Restrictions.eq("product.id",productId));
// the next line doesn't work because I'm already trapped in the "configuration" context..
crit = crit.createCriteria("user").add(
Restrictions.eq("country.id",countryId));
So is there anyway to navigate back "up" the object heirarchy? Or is this approach all wrong?
Also, in this particular case I think I can probably just get away with using createAlias("user") if I could put a constraint on the country_id attribute itself, without linking to the country table. Something like:
Code:
// obviously doesn't work
crit = crit.createAlias("user").add(
Restrictions.eq("country_id",countryId));
I don't really need to restrict the country object, I'm just looking at a property of the user table which happens to be a foreign key.. is there some way to do this with pure criteria or do I have to use a sqlRestriction?
Thanks!