title: Compare Date entities in JPA Criteria API
body: <p><em>Using JPA 2 with EclipseLink implementation.</em></p>
  
  <p>I'm trying to build a dynamic query which should bring me some records persisted after a given date.</p>
  
  <pre><code>CriteriaBuilder builder = em.getCriteriaBuilder();
  CriteriaQuery&lt;Event&gt; criteria = builder.createQuery(Event.class);
  Root&lt;Event&gt; root = criteria.from(Event.class);
  criteria.select(root);
  criteria.distinct(true);
  List&lt;Predicate&gt; predicates = new ArrayList&lt;Predicate&gt;();
  //...
  if (dateLimit != null){
      ParameterExpression&lt;Date&gt; param = builder.parameter(Date.class, "dateLimit");
      predicates.add(builder.lessThanOrEqualTo(root.get("dateCreated"), param));
  }
  </code></pre>
  
  <p><code>lessThanOrEqualTo()</code> and <code>le()</code> are the only two methods in the API which look like may help me in this case. This warning is thrown by the eclipse though:</p>
  
  <pre><code>Bound mismatch: The generic method lessThanOrEqualTo(Expression&lt;? extends Y&gt;, Expression&lt;? extends Y&gt;)
  of type CriteriaBuilder is not applicable for the arguments (Path&lt;Object&gt;, ParameterExpression&lt;Date&gt;).
  The inferred type Object is not a valid substitute for the bounded parameter
  &lt;Y extends Comparable&lt;? super Y&gt;&gt;
  </code></pre>
  
  <p>I can imagine that I'm not taking the correct approach for this problem but I can't find anywhere some tips or pointers for a possible solution.</p>