Hi,
There are atleast a couple of ways to get this value.
i) Send one date from application, pick the other from database.( as done above ).
Concern:
Our application ( Hibernate ) runs on the app server and database on the database server.
Both the machines need not ( and are very unlikely ) be the same.
So, we have to ensure that the dates when compared make sense. ( synchronization, timezones etc...)
Date d = new Date() ; session.createQuery("select ? - p.lastUpdatedDatetime from Petition p").setParameter(0, d).list() ; // Use Bind variables ; Don't hard code.
ii) Don't send a date from the application. Use sysdate (or some equivalent)
Concern:
Not all databases provide the same function to refer to current date.
So, at times, we might have to change the query.
session.createQuery("select sysdate - p.lastUpdatedDatetime from Petition p").list() ; // Oracle
Return type is Double. ( I guess )
------------------------------------------------
Rate the reply if you find it helpful
|