-->
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.  [ 2 posts ] 
Author Message
 Post subject: Use HQL function with criteria API
PostPosted: Tue Nov 22, 2005 8:34 am 
Newbie

Joined: Wed Jan 05, 2005 2:28 pm
Posts: 14
Location: Germany, Munich
Hello,

I have the following HQL statement:

Code:
select  a
from    A a
where   year(a.mydate) = ?



Is it possible to do the same thing with the criteria API? The problem is, that the HQL function year() seems to be not being usable with criteria restrictions.
I don't want to use database specific functions because the code wouldn't be portable anymore.



Bye
Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 7:44 pm 
Newbie

Joined: Sat Oct 30, 2004 4:00 am
Posts: 11
i met exactly same problem before!
MUST use trick:
firstDate=<first date of year>year+01+01;
lastDate=<last date of year>year+12+31;
criteria.add(Restrictions.between("propName", firstDate, lastDate));


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

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.