2

我如何在 HQL 中翻译这个

select * from Customer_data where (status = 7) and 
(datediff(DAY, next_check,getdate()) < 10 ) and 
DATEPART(Hour,next_check) < 10
4

1 回答 1

0

您只需以更一般的方式重构您的查询。

...
Date nextCheck = new Date(); //this is your nextCheck date parameter
Date maxDate = DateHelper.getMaxDate(nextCheck);

Query query = session.createQuery(
    "from CustomerData where status = 7 and date < :maxDate");
query.setParameter("maxDate", maxDate);

List list = query.list();
...

public class DateHelper {

    public static Date getMaxDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(Calendar.DATE, 10);
        cal.set(Calendar.HOUR_OF_DAY, 10);
        cal.set(Calendar.MINUTE, 0);
        cal.set(Calendar.SECOND, 0);
        cal.set(Calendar.MILLISECOND, 0);
        return cal.getTime();
    }
}
于 2012-06-11T09:25:25.613 回答