title: Generating predicate for latest date value
body: <p>I need to create a predicate to fetch data from a table where <code>regId = ? (||) or (&amp;&amp;) estCode = ? &amp;&amp; latest (referralEntryDate)</code></p>
  
  <p>fetch the data for latest date</p>
  
  <pre><code>@Override
  public Predicate toPredicate(Root&lt;ReviewMedicalStatus&gt; root, CriteriaQuery&lt;?&gt; query, CriteriaBuilder cb) {
  
      List&lt;Predicate&gt; predicatesReg = new ArrayList&lt;Predicate&gt;();
  
      if (revStatusDto.getRegId() != null &amp;&amp; !StringUtils.isEmpty(revStatusDto.getRegId())) {
          predicatesReg.add(cb.equal(root.get("regId"), revStatusDto.getRegId()));
      }
      if (revStatusDto.getEstCode() != null &amp;&amp; !StringUtils.isEmpty(revStatusDto.getEstCode())) {
          predicatesReg.add(cb.equal(root.get("estCode"), revStatusDto.getEstCode()));
      }
  
      Expression maxExpression = cb.max(root.get("referralEntryDate"));
      predicatesReg.add(maxExpression);
      //predicatesReg.add(cb.max(root.get("referralEntryDate")));
      return cb.and(predicatesReg.toArray(new Predicate[predicatesReg.size()]));
  }
  </code></pre>
  
  <p>This is failing as the expression can't be passed as a parameter to predicate. How can I get the data for latest <code>referralEntryDate</code>?</p>