I could not figure out how to manipulate time easily using HQL. I *did* read through the forums and found some hints but what I ended up using was a Criteria:
Code:
...
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, 0-days);
...
Session session = (Session)super.getEntityManager().getDelegate();
Object countObject = session.createCriteria(UsedMonitor.class)
.setProjection(Projections.rowCount())
.add(Restrictions.gt("timestamp", calendar.getTime()))
.uniqueResult();
This works perfectly but it does make my class Hibernate aware. What I understand to be the problem is that different db implementations have completely different ways of handling date manipulation, i.e.:
Oracle: CURRENT_TIMESTAMP - days
MySQL: CURRENT_TIMESTAMP - (INTERVAL days DAY)
HyperSQL: ??
So my question is have I done it the "right" way or is there a way to perform the date manipulation in a more generic way using HQL?