开发者

How to use the CURRENT_DATE function in a hibernate criterion?

开发者 https://www.devze.com 2023-01-18 00:53 出处:网络
I want to translate the following HQL into Criteria notation: from Deal where CURRENT_DATE between startDate and endDate

I want to translate the following HQL into Criteria notation:

from Deal
where CURRENT_DATE between startDate and endDate

I tried using Restrictions.betw开发者_开发问答een but it doesn't recognize current_date

Criteria c = session().createCriteria(Deal.class)
   .add(Restrictions.between("CURRENT_DATE", "startDate", "endDate");


Just use the UGLY java Calendar!

Calendar c = new GregorianCalendar();
c.set(Calendar.HOUR_OF_DAY, 0);
c.set(Calendar.MINUTE, 0);
c.set(Calendar.SECOND, 0);
c.set(Calendar.MILLISECOND, 0);

Date currentDate = c.getTime();

Criteria criteria = session.createCriteria(Deal.class)
.add(Restrictions.gt("startDate", currentDate))     
.add(Restrictions.lt("endDate", currentDate)); 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号