How should I go about setting up HQL condition that would select all the object who's date property is older than 3 hours from now.
HQL doesn't support datediff, but if you still want to use datediff, you should use createNativeQuery() or createSQLQuery() to write that in sql. In your example, you just need the id anyway, not entity object, so this should be enough.
Keywords like SELECT, FROM, and WHERE, etc., are not case sensitive, but properties like table and column names are case sensitive in HQL.
This should work.
Calendar cal = Calendar.getInstance();
cal.add(Calendar.HOUR_OF_DAY, 3);
Query q = session.createQuery("from table where date < :date");
q.setCalendarDate("date", cal);
q.list();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With