MatBanik
MatBanik

Reputation: 26860

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.

Upvotes: 6

Views: 11458

Answers (1)

Robby Pond
Robby Pond

Reputation: 73484

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();

Upvotes: 7

Related Questions