title: Building a query using NOT EXISTS in jpa criteria api
body: <p>I have two tables named as table1 ,table2.Both the tables are having same no  of fields.There is no relation between these two tables.My requirement is I want all the records in table1 which are not there in table2. So I have written a query using Criteria API. But it is not giving the correct result. As I am new to this JPA and criteria API, can any one point me where I am doing wrong.The below code I am using to do this.</p>
  
  <pre><code>CriteriaBuilder cb = mediationEntityManager.getCriteriaBuilder();
  CriteriaQuery&lt;Table1&gt;  cq = cb.createQuery(Table1.class);
  Root&lt;Table1&gt; table1 = cq.from(Table1.class);
  cq.select(table1)
  
  Subquery&lt;Table2&gt; subquery =  cq.subquery(Table2.class)
  Root table2 = subquery.from(Table2.class)
  subquery.select(table2)
  cq.where(cb.not(cb.exists(subquery)))
  TypedQuery&lt;Table1&gt; typedQuery = mediationEntityManager.createQuery(cq); 
  List&lt;Table1&gt; resultList = typedQuery.getResultList();
  </code></pre>
  
  <p>MySQL Query :</p>
  
  <pre class="lang-sql prettyprint-override"><code>SELECT table1 
  FROM   table1 table1 
  WHERE  NOT EXISTS (SELECT table2 
                     FROM   table2 table2 
                     WHERE  table2.name = table1.name 
                            AND table2.education = table1.education 
                            AND table2.age = table1.age) 
         AND table1.name = 'san' 
         AND table1.age = '10'; 
  </code></pre>
  
  <p>I need the JPA criteria API query for the above mentioned MySQL query.</p>