title: JPA and Hibernate: compare only time portions of timestamps
body: <p>I'm using Hibernate through JPA and I need to filter records by the time portion of their <code>Date</code> property .</p>
  
  <pre><code>public class Foo {
      Date getDateTime() {
          // Returns a date and time value.
      }
  }
  
  Time startTime = ...;
  Time endTime = ...;
  
  TypedQuery&lt;Foo&gt; query = entityManager.createQuery("SELECT foo FROM Foo foo where :startTime &lt;= foo.dateTime AND foo.dateTime &lt;= :endTime", Foo.class);
  query.setParameter("startTime", startTime);
  query.setParameter("endTime ", endTime);
  </code></pre>
  
  <p>Of course this will not work because you can't directly compare a <code>Date</code> and a <code>Time</code>. If this were a SQL query, then I would use a few DBMS-specific date functions to compare them, but how do you compare a Date and a Time in JPA?</p>