I think you have problems because you are using the setDate
(correct me if I am wrong) and the setDate
method:
Binds the date (time truncated) of this Date
object to the named query parameter.
Use setTimestamp
instead, which binds the date and time of this Date
object:
java.util.Date startDate = … ; java.util.Date finishDate = … ; Query query = session.createQuery("from YourTable where event_date >= :startDate and event_date < :finishDate"); query.setTimestamp("startDate", startDate); query.setTimestamp("finishDate", finishDate);
ps: don't forget to use the java.util.Date
and NOT java.sql.Date
objects.
source share