I have a problem with a set of objects in a hbm file. I have a table with students that has fk to table schools. Other table with classes that has a FK to schools. So in the hbm of schools I have a set of classes. Imagine that I want to get the students that study in the school x and study in the class x. The problems is that I cannot do this:
From the table students I do:
filter.addCriterion("school", objectSchool)//fk filter.addAlias("schools", "schools"); filter.addAlias("schools.classes", "class"); filter.addCriterion(Restrictions.eq("class.classId", new Integer(id)));
But the sql is not correct, I mean , I get all the students from the school objectSchool and not only the student from the class x. My question is:
How to resolve this with Criterions and not with HQL.
Thanks
|