Sin开发者_C百科ce I want to store date and time for each data in table X
, I use
@Temporal(TemporalType.TIMESTAMP)
private Date dateProcess; //java.util.Date
and this work great. But now I want to create query that return all data in the same date. So I try
SELECT c from X c where c.dateProcess = : dateProcess
then I would pass in a java.util.Date
for parameter dateProcess
, but the returned result List is empty. I guess it must be that time
comes into place here. So if the two dates does not have the exact date and time, it would not be equal, that would explain why my returned result list is empty. So how do I return a List of data base on a Date (dont care about time) in this scenario?
Just use a date range, specify the start and end time. > startTime and < endTime
Try TemporalType.DATE
If you need to retain the time, but only query for the date, then you have options:
- use JPQL date function -
day(..)
,months(..)
,year(..)
- use
<
and>
for date ranges (as James suggested) - store the date and time in two different columns.
Does specifiying temporal type as Date
help or would you lose precision?
Currently I do like this
Using HQL to query on a date while ignoring the time on Oracle
I haven't try this one yet. So not sure it will work. date_format is registered function in release.
http://www.docjar.com/html/api/org/hibernate/dialect/MySQLDialect.java.html
精彩评论