title: Criteria query combine and predicates and or predicates in where method
body: <p>The <code>where</code> method of CriteriBuilder </p>
  
  <blockquote>
    <p>restricts the query result according to the conjunction of the specified restriction predicates</p>
  </blockquote>
  
  <p>In other words, concatenate all predicates with AND. I pass a list of predicates to this method in this way:</p>
  
  <pre><code>criteria.where(preds.toArray(new Predicate[0]));
  </code></pre>
  
  <p>The result query is something like this:</p>
  
  <pre><code>... where p1 and p2 and p3
  </code></pre>
  
  <p>however what I need is:</p>
  
  <pre><code>... where p1 and p2 or p3
  </code></pre>
  
  <p>I tried to use two list of preds, one for "ANDS" and another one for "ORS":</p>
  
  <pre><code>if(preds.isEmpty() &amp;&amp; !orPreds.isEmpty()) {
      criteria.where(cb.or(orPreds.toArray(new Predicate[orPreds.size()])));
  }
  else if(!preds.isEmpty() &amp;&amp; !orPreds.isEmpty()) {
      criteria.where(cb.and(preds.toArray(new Predicate[preds.size()])), 
      cb.or(orPreds.toArray(new Predicate[orPreds.size()])));
  }
  else {
      criteria.where(preds.toArray(new Predicate[0]));
  }
  </code></pre>
  
  <p>But the result query is the same:</p>
  
  <pre><code>... where p1 and p2 and p3
  </code></pre>
  
  <p>Any idea?</p>