我有条件检查当前日期 - 3。
select * from TABLE_1 SYSDATE-3 >= TABLE_1.created_date
我应该如何用Hibernate查询语言编写?
答案 0 :(得分:5)
对于Oracle SQL方言,请使用sysdate()
,例如:
select e
from Entity e
where (e.endDate is null or (e.endDate > sysdate()))
这适用于orm.xml
或使用<named-query>
对于您的特定查询“过去三天内尚未创建的所有行”,请使用以下命令:
select e from Entity e where to_date(sysdate() - 3) >= e.created_date
答案 1 :(得分:1)
您需要使用实体编写HQL。
http://docs.jboss.org/hibernate/orm/4.1/manual/en-US/html_single/#queryhql-examples
有一些使用sysdate的例子。