2

According to EclipseLink documentation it supports subqueries in the select clause (even if JPA doesn't require it).

When I try to use this feature in JPA Criteria API:

myCriteriaQuery
.multiselect(Arrays.asList(mySubquery, ...))
.where(...)

there is an error:

java.lang.ClassCastException: org.eclipse.persistence.internal.jpa.querydef.SubQueryImpl cannot be cast to org.eclipse.persistence.internal.jpa.querydef.SelectionImpl

    at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.createCompoundQuery(CriteriaQueryImpl.java:511)
    at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.getDatabaseQuery(CriteriaQueryImpl.java:447)
    at org.eclipse.persistence.internal.jpa.querydef.CommonAbstractCriteriaImpl.translate(CommonAbstractCriteriaImpl.java:198)
    at org.eclipse.persistence.internal.jpa.querydef.CriteriaQueryImpl.translate(CriteriaQueryImpl.java:691)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createQuery(EntityManagerImpl.java:1551)

Any hint why it doesn't work?

ragnor
  • 2,498
  • 1
  • 22
  • 25
  • The documentation you linked shows the Criteria#Subquery and doesn't mention selecting a subquery. The only documentation I found shows it supporting a subquery in the from clause, and in JPQL not criteria queries - which might not fit into the JPA criteria classes. https://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Basic_JPA_Development/Querying/JPQL#Sub-selects_in_FROM_clause – Chris Mar 18 '16 at 13:54
  • So how to understand the first sentence: "Subqueries can be used in the Criteria API in the *select*, where, order, group by, or having clauses." Doesn't it mean that select in select clause can be used? – ragnor Mar 19 '16 at 10:19

0 Answers0