Wednesday, January 2, 2013

HQL: Query By Date Without The Time

In HQL/JPA There are a couple ways to query off of a date in a database without taking into account the time, but most of them require you fiddle with the date objects before handing them off to the query or to use native SQL functions. 

However, here is a simple way to query, ignoring the time, and only using hibernate expressions.

day(g.transactionDate) = day(:transactionDate) and month(g.transactionDate) = month(:transactionDate) and year(g.transactionDate) = year(:transactionDate)

And here is a link to the relevant Hibernate Docs.

No comments:

Post a Comment