开发者

How to use the CURRENT_DATE function in a hibernate criterion?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜