0

我从以下 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 with Restrictions,但我还需要检查该事件是否已启用。我怎样才能完成这个日期比较?

4

1 回答 1

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();

这行得通吗?

于 2013-09-09T22:49:52.057 回答