egervari wrote:
I have a one-to-many association from table A to B. B has a boolean field called is_accessed. I'd like to write a query that gives me all the A's where all it's own B's are true (or false), but I'm having a real hard time doing this.
I have two tables: Department and Employee with a one-to-many from Department to Employee. I have a char(1) field in Employee which could be 'Y' or 'N' (but not null). In my case, this works to get all the Departments where all of the department employees are 'Y':
Code:
Iterator deptIterator = session
.iterate("from Department as dept where exists "
+ "(select emp from Employee as emp "
+ "where emp.active = 'Y' and emp.dept = dept.id)"
+ "and not exists (select emp from Employee as emp "
+ "where emp.active = 'N' "
+ "and emp.dept = dept.id)");
HTH,
Maury