Hibernate 的日期相减,兼容主流关系型数据库;
用hibernate带的CURRENT_DATE(),
public List<User> getListBeAboutToExpiredUsers(){
//, CURRENT_TIMESTAMP()-updatePwdDate
String Hql = "SELECT loginId,userName, updatePwdDate from User where state=1 and (CURRENT_DATE()-updatePwdDate) between 10 and 20";
List<User> list = this.dao.getHSession().createQuery(Hql).list();
System.out.println(list);
/*String sql = "SELECT * from PURE_USER WHERE STATE=1 and (sysdate-UPDATE_PWD_DATE) between 10 and 14";
Query query = this.dao.getHSession().createSQLQuery(sql.toString()).addEntity(User.class);
return query.list();*/
return list;
}