QueryDSL - 将子查询添加到 FROM 语句中 (2021)

QueryDSL - add subquery into FROM statement (2021)

根据@Timo Westkämper(参见QueryDSL - add subquery into FROM statement),2013 年可以在 FROM 子句中包含子查询。如今这似乎不再可能,因为 JPQL 规范不允许这样做:

(https://docs.oracle.com/cd/E12839_01/apirefs.1111/e13946/ejb3_langref.html#ejb3_langref_subqueries) Subqueries are restricted to the WHERE and HAVING clauses in this release. Support for subqueries in the FROM clause will be considered in a later release of the specification.

我不明白这怎么可能。您能否确认无法在 querydsl 4.4.x?

的 FROM 子句中使用子查询

如果您仔细阅读链接的问题,Timo 正在谈论“Querydsl SQL”。那就是直接发出 SQL 的 QueryDSL 模块,完全绕过了 JPA。

也就是说,您可以在使用普通 SQL 时在 from 子句中使用子查询,但在使用 JPQL 时则不能。

这就是方法 com.querydsl.sql.SQLCommonQuery.from 具有 overload that takes a SubQueryExpression, while the method com.querydsl.jpa.JPQLQuery.from doesn't have such an overload 的原因。