Hi all,
I've been banging my head against this problem for a couple of days and coming to the conclusion that there's something fundamentally wrong with my way of thinking and the query I'm trying to build.
To begin I'm using Hibernate 3.2.1 against Oracle 10 XE.
My project concerns cars with options on cars linked together using an association entity class, basically very similiar to the example in the reference manual; Employer<->EmploymentPeriods<->Employee. The mappings are two bidirectional one-to-many associations, again same as said example.
Following the paradigm of said example I would want to return all employees who have worked for certain employers. Querying on a single employer or firing an OR statement for certain employers works but I cant return employees who have worked for employer1 AND employer2.
Here's the criteria setup I'm working on
Criteria crit = session.createCriteria(Employee.class);
Criteria critEmpPers = crit.createCriteria("employmentPeriods");
Criteria critEmployer = critEmpPers .createCriteria("employer");
critEmployer.add(Restrictions.conjunction()
.add( Restrictions.idEq(new Long(1)))
.add( Restrictions.idEq(new Long(3))));
If I use the disjunction I get all employees who have worked for employers 1 or 3 but I can't get those that have worked for 1 and 3.
What am I missing, someone give me a kick plz!
Colin
|