title: Hibernate Criteria query Collections contains certain elements
body: <p>I have some problems with <code>Criteria</code>. I have a <code>Job</code> class that contains a set of <code>Skills</code>.</p>
  
  <p>The problem comes when I want to filter jobs that contain 2 skills, for example, all jobs that contains skill with id 1 and 3.</p>
  
  <p>Now I have this:</p>
  
  <pre><code>for (Skill skill : job.getSkills()) {
      ids.add(skill.getId());
  }
  
  criteria.createAlias("skills", "skill");
  criteria.add(Restrictions.in("skill.id", ids));
  </code></pre>
  
  <p>but it gives me jobs that contain skill 1 or 3, not only those with both skills.
  How can I do this?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code>criteria.createAlias("Job.skills", "skill");    
  Conjunction and = Restrictions.conjunction();   
  
  for (Skill skill : job.getSkills()) {
      and.add(Restrictions.eq("skill.id", skill.getId()));
  }
  criteria.add(and);
  </code></pre>
  
  <p>I've tried this but the sql is <code>and (skill1_.ID=? and skill1_.ID=?)</code> with no results</p>