title: Union in Spring JPA Or Specification
body: <p>Trying to create criteria builder for below query. However seems UNION is not supported by JPA. Any thoughts ?</p>
  
  <pre><code>SELECT * 
  FROM   firsttable i1 
  WHERE  EXISTS (SELECT 1 
                 FROM   secondtable 
                 WHERE  id = i1.fid 
                        AND flag = 'Flag1') 
         AND EXISTS (SELECT 1 
                 FROM   secondtable 
                 WHERE  id = i1.fid 
                        AND flag = 'Flag2') 
  
  UNION 
  
  SELECT * 
  FROM   firsttable i1 
  WHERE  NOT EXISTS (SELECT 1 
                 FROM   secondtable 
                 WHERE  id = i1.fid 
                        AND flag = 'Flag1') 
         AND EXISTS (SELECT 1 
                 FROM   secondtable 
                 WHERE  id = i1.fid 
                        AND flag = 'Flag2'); 
  </code></pre>