A subquery returns an ID instead of an entity #3679
Unanswered
littlebytesof
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In the environment as follows:
SpringBoot 3.2.2 (Kotlin)
QueryDSL 5.0.0
Hibernate 5.6.15.Final
, a subquery expression within the JPAQueryFactory.select method causes the following exception:
class java.lang.Long cannot be cast to class [CLASS_PATH] (java.lang.Long is in module java.base of loader 'bootstrap'; [CLASS_PATH] in unnamed module of loader org.springframework.boot.loader.launch.LaunchedClassLoader @279f2327); [cause] null; [class] class java.lang.ClassCastException
A relevant code example can be simplified as follows: (The example is simple enough so that I could use a join operation rather than a subquery, but the real case requires a more convoluted query)
val alias = Expressions.path(JpaEntityB::class.java, "entityB")
val subquery = this.queryFactory
.select(this.jpaEntityB)
.from(this.jpaEntityB)
.where(this.jpaEntityB.id.eq(this.jpaEntityA.jpaEntityB.id))
.asSubquery(alias.toString())
val fetched = this.queryFactory
.select(this.jpaEntityA, subquery)
.from(this.jpaEntityA)
.fetch()
.map {
it.get(alias) // This would cause the above-mentioned exception.
// it.get(1, Long::class.java) // This would return the ID of the entity without causing an exception.
}
It seems that the component of the fetched tuples that corresponds to the entityB returns its ID instead of itself. No compilation error is caused.
The same codes are run without a problem in SpringBoot 2.7.x (Kotlin) with the same QueryDSL version, returning the entityB as expected.
Beta Was this translation helpful? Give feedback.
All reactions