title: Querying with Timestamps using SpringBoot and JPA Criteria Query in custom repository
body: <p>How do you query based off timestamps in custom JPA repositories using JPA Criteria Query?</p>
  <p>I have a <code>startTime</code> and <code>endTime</code> that I want to use to query for entires with a field <code>time</code> between them, but I need to do this in a custom repository because there are a lot of other fields that I need to use to build a complex query.</p>
  <p>I've can succcessfully build up a complex query and get correct results, except when I try to query by <code>startTime</code> and <code>endTime</code>. I've been trying to do something like the following but with no luck</p>
  <pre><code>@PersistenceContext private EntityManager em;
  ...
    final CriteriaBuilder cb = this.em.getCriteriaBuilder();
    final CriteriaQuery&lt;AutoenrollmentEvent&gt; cr = cb.createQuery(Event.class);
    final Root&lt;AutoenrollmentEvent&gt; root = cr.from(Event.class);
    final List&lt;Predicate&gt; predicates = new ArrayList&lt;&gt;();
    ...
      predicates.add(cb.between(root.get(&quot;time&quot;), data.getStartTime(), data.getEndTime()));
    ...
    cr.select(root).where(predicates.toArray(new Predicate[0]));
    return this.em.createQuery(cr).getResultList();
  </code></pre>
  <p>where <code>data.getStartTime()</code> and <code>data.getEndTime()</code> are of type <code>java.sql.Timestamp</code>.</p>
  <p>The idea is to get all the entries with a timestamp in field <code>time</code> between <code>startTime</code> and <code>endTime</code>.</p>
  <p>Any ideas on how to do this?</p>
  <p>Thanks.</p>