0

In 2013 according to @Timo Westkämper (see QueryDSL - add subquery into FROM statement) it was possible to include a subquery in a FROM clause. Nowadays it seems this is not longer possible as JPQL specification does not allow it:

(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.

I don't get how is this possible. Can you confirm it's not possible to use subqueries in a FROM clause in querydsl 4.4.x?

jaime737
  • 23
  • 4

1 Answers1

1

If you read the linked question carefully, Timo is talking about "Querydsl SQL". That's the QueryDSL module that directly emits SQL, completely bypassing JPA.

That is, you can use a subquery in a from clause when using plain SQL, but not when using JPQL.

That's why the method com.querydsl.sql.SQLCommonQuery.from has an overload that takes a SubQueryExpression, while the method com.querydsl.jpa.JPQLQuery.from doesn't have such an overload.

meriton
  • 68,356
  • 14
  • 108
  • 175
  • This is the correct answer. However it is possible to use queries in the from clause in JPA using lateral joins or common table expressions using the Blaze-Persistence QueryDSL integration: https://persistence.blazebit.com/documentation/1.5/core/manual/en_US/#querydsl-integration . Blaze-Persistence is a library that extends the JPA language with new features. – Jan-Willem Gmelig Meyling May 10 '21 at 06:40