我想将以下HQL转换为Criteria表示法:
from Deal
where CURRENT_DATE between startDate and endDate
我尝试使用Restrictions.between但它无法识别current_date
Criteria c = session().createCriteria(Deal.class)
.add(Restrictions.between("CURRENT_DATE", "startDate", "endDate");
答案 0 :(得分:1)
只需使用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));