I have some problems with Criteria.I have a Job class that contains a set of Skills.
The problem comes when i want to filter jobs that contains 2 skills for example(all jobs that contains skill with id 1 and 3).
USING:Code:
for(Skill skill:job.getSkills()){
ids.add(skill.getId());
}
criteria.createAlias("skills", "skill");
criteria.add(Restrictions.in("skill.id", ids));
it gives me jobs that contains skill 1 or 3,not only those with both skills.
USING:Code:
Conjunction and = Restrictions.conjunction();
for(Skill skill:job.getSkills()){
and.add(Restrictions.eq("skill.id",skill.getId()));
}
criteria.add(and);
it returns me nothing and the query looks like :
Code:
and (skill1_.ID=? and skill1_.ID=?)
same skill alias.
Please give me some ideas.Thanks