我从以下Hibernate代码开始:
@SuppressWarnings("unchecked")
List<Event> events = (List<Event>) session.createQuery(
"FROM Event e WHERE e.enabled = TRUE e.date + 31557600 < :now"
)
.setDate("now", new Date())
.list();
添加日期不起作用。我使用Criteria和Restrictions进行了调查,但我还需要检查该事件是否已启用。我该如何完成这个日期比较?
答案 0 :(得分:1)
Calendar currDate = Calendar.getInstance();
currDate.add(<field>, -31557600); // I guess field will be Calendar.MILLISECOND
然后根据您的查询编写
@SuppressWarnings("unchecked")
List<Event> events = (List<Event>) session.createQuery(
"FROM Event e WHERE e.enabled = TRUE e.date > :now"
)
.setDate("now", currDate.getTime())
.list();
这有用吗?