JPA CriteriaQuery compare Timestamp ignore time portion
<p>Let say I have a column in Oracle DB like this:</p>

<p><code>SOMETHING_TS     TIMESTAMP WITH TIME ZONE</code></p>

<p>And I would like to use CriteriaQuery to filter by this column.</p>

<p>I can used native query to achieve this:</p>

<pre><code>    SELECT * 
    FROM SOMETHING
    WHERE TRUNC(SOMETHING_TS) = TO_DATE('2016-12-08','YYYY-MM-DD');
</code></pre>

<p>But in Java I have failed to do so, below is my sample code:</p>

<pre><code>    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery&lt;MyClass&gt; cq = cb.createQuery(MyClass.class);
    Date date = new Date();

    predicates.add(cb.equal(cb.function("TRUNC", Date.class, myClass.get("somethingTs")), cb.function("TO_DATE", Date.class, cb.parameter(Date.class, "somethingTs"), cb.literal("YYYY-MM-DD"))));

    Predicate[] predArray = new Predicate[predicates.size()];
    predicates.toArray(predArray);

    cq.where(predArray);

    TypedQuery&lt;MyClass&gt; query = em.createQuery(cq);
    query.setParameter("somethingDt", date);
</code></pre>