I have a field of time Timestamp in my MySQL database which is mapped to a date datatype in my Bean.
Now I want a query by which I can fetch all records in the database for which the difference between the current timestamp and the one stored in the database is > 20 minutes.How can I do it?
What I want is
select T from MyTab T where T.runTime - c开发者_JAVA百科urrentTime > 20 minutes
I tried the following
Query query = getSession().createQuery("Select :nw - T.runTime from MyTab T");
query.setDate("nw", new Date());
It returns some values like -2.0110930179433E13 .
How can I model this in SQL/Hibernate? Even if I get some native SQL query (MySQL) then it's ok.
I guess this link might help:
https://forum.hibernate.org/viewtopic.php?p=2393545
and this one is also very helful:
Hibernate Dialects + datediff function
Hope it helps.
精彩评论