如何编写一个hibernate条件或hql,它返回数据库中超过两周的对象,知道这些对象有一个creationDate字段?
由于
答案 0 :(得分:0)
伪代码
Calendar olederThanTwo = Calendar.getInstance() - 2_weks;
select creationDate < olederThanTwo;
代码草图
@Entity
class Persistent {
@Column
private Calendar creationDate;
}
List<Persistent> getOlderThan(Calendar calendar) {
session.createCriteria(Persistent.class);
session.add(Restrictions.lt("creationDate", calendar));
return session.list();
}
Calendar twoWeeksBefore = ...;
List<Persistent> result = getOlderThan(twoWeeksBefore);
答案 1 :(得分:0)
您可以尝试使用以下内容:
List <Object> findByCreationDate(LocalDate dt);
并将localdate传递给方法,如下所示:
LocalDate subtracted = dt.minusWeeks(2);