【发布时间】:2015-03-31 16:23:51
【问题描述】:
我需要在现有的 HQL where 子句中插入一个变量,如下所示:
java.sql.Timestamp currentDate = new Timestamp(System.currentTimeMillis());
Query q = em.createQuery("from fAdjustmentReason a where a.startDate >= " + currentDate + " and a.endDate <= " + currentDate);
执行上述操作时,我收到以下错误消息:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: 18 near line 1, column 79
[from gov.va.med.domain.fee.AdjustmentReason a where a.startDate >= 1969-12-31 18:00:00.0 and a.endDate <= 1969-12-31 18:00:00.0]
我是否应该在现有的 AdjustmentReason 模型类中添加一个 currentDate 字段,即使它不在数据库中以使这更简单?
非常感谢任何帮助!
【问题讨论】:
-
提示:对于日期,您可以使用
BETWEEN子句,例如。SELECT a FROM entity WHERE startDate BETWEEN :startDate AND :endDate
标签: java oracle hibernate toad