【发布时间】:2013-10-14 06:29:59
【问题描述】:
如何在Hibernate SQL 或HSQL 中编写查询以显示从当前日期起一周或1 个月的数据?
【问题讨论】:
如何在Hibernate SQL 或HSQL 中编写查询以显示从当前日期起一周或1 个月的数据?
【问题讨论】:
考虑一个具有 _productId 和 _productCreatedDate 的实体产品 所以
StringBulider sql=new StringBuilder();
sql.append("select _productId,_productCreatedDate from Product where");
sql.append("_productCreatedDate between :currentDate and :dateOneMonthBefore")
sessionFactory.getSession().createQuery(sql.toString()).setParameter("currentDate",newDate())
.setParameter("dateOneMonthBefore",new Date("Enter the month before the current date"))
【讨论】: