title: CriteriaBuilder collection values
body: <p>I have a scenario where I have to get the list of all masters who have no students (set is empty) and also students whose status is cancelled</p>
  
  <pre><code>@Entity    
  @Table(name="Masters")   
  public class Master {    
  
      @Id    
      private String id;
  
      @One To Many mapping here
      private Set&lt;Student&gt; students = new HashSet&lt;&gt;();
  }
  
  @Entity   
  @Table(name="Students")   
  public class Student {
  
      @Id
      private String id;
  
      @Column(name = "Status")
      private String status;
  }
  
  I have my code as 
  
  final CriteriaBuilder cb = getEM().getCriteriaBuilder();    
  final CriteriaQuery&lt;Tuple&gt; criteriaQuery = cb.createTupleQuery();    
  final Root&lt;Master&gt; mvRoot = criteriaQuery.from(Master.class);
  Predicate predicate = cb.conjunction();    
  this gives me list of masters who dont have any students
  
  predicate = cb.and(predicate, cb.isEmpty(mvRoot.join(Master.STUDENTS)));     
  </code></pre>
  
  <p>This is giving the list of masters with student status cancelled</p>
  
  <pre><code>final Join&lt;Master, Set&lt;Student&gt;&gt; studentJoin = mvRoot.join(Master.STUDENTS);    
  predicate = cb.and(predicate, cb.equal(studentJoin.get(Student.status), "Cancelled"));    
  </code></pre>
  
  <p>I am not able to fetch both at a time, and if I club both i am just getting masters with students status cancelled and not the masters with no students</p>
  
  <p>Can some one please advise me.</p>