CURRENT_TIMESTAMP算法 - QuerySyntaxException

时间:2017-02-16 06:22:05

标签: jpa spring-data-jpa

我正在尝试在spring-jpa界面中添加@Modifying方法,其中包含以下内容

@Modifying
@Transactional
@Query("update Contact cc set cc.bar=?2 where cc.foo = ?1 AND cc.createdTime>CURRENT_TIMESTAMP - interval '60' minute")
public Contact setFixedBarFor(String foo, boolean bar);

但我得到以下异常,..

Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: interval near line 1, column 136 [update Contact cc set cc.foo=?2 where cc.bar = ?1 AND cc.createdTime>CURRENT_TIMESTAMP - interval '20' minute]
    at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
    at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:91)
    at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:288)

注意: 以下作品:

update Contact cc set cc.bar=?2 where cc.foo = ?1 AND cc.createdTime>CURRENT_TIMESTAMP

update Contact cc set cc.bar=?2 where cc.foo = ?1 AND cc.createdTime>CURRENT_TIMESTAMP-1

我想要算术内置,而确定它是什么,我做错了。

1 个答案:

答案 0 :(得分:0)

结束以下

update Contact cc set cc.bar=?2 where cc.foo = ?1 AND cast((CURRENT_TIMESTAMP - (1/24)) as timestamp) between cc.createdTime and CURRENT_TIMESTAMP")

感谢@Burhan提供the指针以及此SO answer