SpringData : is it possible to have subqueries in the Query annotation?(SpringData:查询注释中是否可以有子查询?)
问题描述
我想知道是否可以在@Query 注释中包含子查询(org.springframework.data.jpa.repository.Query;)
I would like to know if it is possible to have subquery in a @Query annotation (org.springframework.data.jpa.repository.Query;)
我在第一个子查询括号中收到 QuerySyntaxException.
I am getting a QuerySyntaxException on the first subquery parentesis.
这是我的查询
@Query(value="select c1 from ComplaintModel c1, "
+ "(select c2.id, min(cb.termDate) minDate from ComplaintModel c2 "
+ "join c2.complaintBullets cb join cb.status s where s.code = ?1 "
+ "group by c2.id) tmp where c1.id = tmp.id order by tmp.minDate")
谢谢!
推荐答案
不,JPQL查询的select子句中不能有子查询.
No, it is not possible to have subquery in the select clause in JPQL query.
JPQL 支持 WHERE 和 HAVING 子句中的子查询.它可以(至少)是 ANY、SOME、ALL、IN、EXIST 表达式的一部分,当然也可以使用普通的条件表达式:
JPQL supports subqueries in WHERE and HAVING clauses. It can be (at least) part of ANY, SOME, ALL, IN, EXIST expressions, and of course it can be used normal conditional expressions:
SELECT a
FROM A a
WHERE a.val = (SELECT b.someval
FROM B b
WHERE b.someotherval=3)
这篇关于SpringData:查询注释中是否可以有子查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SpringData:查询注释中是否可以有子查询?


- Java包名称中单词分隔符的约定是什么? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- 如何使用WebFilter实现授权头检查 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01