【发布时间】:2021-02-19 06:33:21
【问题描述】:
我需要能够为我的后端应用程序检索过去 6 个月的订单。
@Query("Select ord From orders ord WHERE ord.created_date <= (current_date - INTERVAL '6 months')")
List<Order> findOrders();
unexpected token: INTERVAL near line 1, column 70 [Select ord From orders ord WHERE ord.created_date <= (current_date INTERVAL '6 months')
经过一番研究,我发现 JPA 不支持 INTERVAL 定义。 有存档这个特殊功能的解决方法吗?
【问题讨论】:
-
试试
(current_date - cast('6 months' AS INTERVAL))。它应该可以工作,但我没有足够的信心将其发布为答案。 -
试过你的版本。不幸的是,它不起作用
-
在 JPA 或数据库中解析时它会崩溃吗?错误消息会很有用。
-
JPQL 和 HQL 不支持区间,您必须使用 Adam Gaj 提供的解决方案
标签: sql spring-boot hibernate jpa