【发布时间】:2019-01-27 01:07:12
【问题描述】:
我尝试在 Spring Data JPA Repository 中创建一种不同的方法,该方法应该将给定的小时数添加到时间戳。
public interface ActivationCodeRepository extends CrudRepository<ActivationCode, Long> {
@Query(value = "select a from ActivationCode a where a.creationTime + INTERVAL '1 hour' * :hoursAgo <= CURRENT_TIMESTAMP and a.type = :type and a.account = account")
List<ActivationCode> getAllAddedAtLeastXHoursAgo(@Param("account") Account account, @Param("type") int type, @Param("hoursAgo") int hoursAgo);
}
因为它不工作:
- INTERVAL '1 小时' * :hoursAgo
完全正确:
'1 小时'
IDE 下划线并给出此错误:
、、GROUP、HAVING 或 ORDER 预期。
我已经尝试做一些研究,并找到我应该如何将给定的时间添加到 creationTime 但在任何地方都找不到。
【问题讨论】:
-
我不认为像 JPA 这样的混淆层支持
INTERVAL文字。您将需要一个本机查询。
标签: java postgresql hibernate spring-data-jpa