Nested OR, AND in CriteriaBuilder, Predicate
<p>writing following criteria</p>

<pre><code>    Date vardate = 'Tue Jan 01 00:00:00 IST 2100';    
    public Predicate toPredicate(
                        Root&lt;T&gt; root,
                        CriteriaQuery&lt;?&gt; query, CriteriaBuilder cb) {               
                        List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();  
                            predicates.add(cb.equal(root.get(LINE_OF_BUSINESS_ID), lobId));
//Predicate a = cb.and(cb.isNotNull(stateSuretyRates.&lt;Date&gt;get(EXP_DATE)),
                            cb.greaterThanOrEqualTo(stateSuretyRates.&lt;Date&gt;get(EXP_DATE),effDate));
        return cb.and(predicates.toArray(new Predicate[] {}));
        }
</code></pre>

<p>and query is </p>

<pre><code>select ... from table t Where t.business = 1 and
(
(t.StartA &lt;= 'some EndB') and (t.EndA &gt;= 'some StartB') and (t.EndA is not null) and ('some EndB' is not null)
OR
(t.StartA &lt;= 'some EndB') and (vardate &gt;= 'some StartB') and (t.EndA is null) and ('some EndB' is not null)
OR
(t.StartA &lt;= vardate) and (t.EndA &gt;= 'some StartB') and (t.EndA is not null) and ('some EndB' is null)
OR
(t.StartA &lt;= vardate) and (vardate &gt;= 'some StartB') and (t.EndA is null) and ('some EndB' is null)
)
</code></pre>

<p>Please suggest, how to write predicate and predicates </p>