Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate HQL query for finding entries older than 3 hours

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.

like image 808
MatBanik Avatar asked Mar 08 '11 21:03

MatBanik


People also ask

How do I use datediff in HQL?

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.

Can we use select * in HQL?

Keywords like SELECT, FROM, and WHERE, etc., are not case sensitive, but properties like table and column names are case sensitive in HQL.


1 Answers

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();
like image 86
Robby Pond Avatar answered Sep 21 '22 09:09

Robby Pond