-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Manipulating time with HQL
PostPosted: Sat Dec 19, 2009 7:26 pm 
Newbie

Joined: Sat Dec 19, 2009 7:17 pm
Posts: 1
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?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.