You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
EclipseLink is rejecting JPQL SELECT NEW clauses where an entity contains an attribute that is an ElementCollection.
For example, SELECT o.comments FROM Rating o WHERE o.id = :id where the column comments is an ElementCollection is correctly returned as a result set.
We can see from the SQL generated by EclipseLink that a JOIN is required to get the data from the Rating_COMMENTS table:
SELECTt1.COMMENTSFROM RATING t0
LEFT OUTER JOIN Rating_COMMENTS t1
ON (t1.Rating_ID=t0.ID)
WHERE (t0.ID= ?)
However, when we try to use o.comments in a SELECT NEW query like the one below:
SELECT NEW
io.openliberty.jpa.data.tests.models.Rating( o.id, o.item, o.numStars, o.reviewer, o.comments )
FROM Rating o
WHEREo.id= :id
The following error is thrown:
Exception [EclipseLink-0] (Eclipse Persistence Services - 5.0.0.v202408071314-43356e84b79e71022b1656a5462b0a72d70787a4): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT NEW io.openliberty.jpa.data.tests.models.Rating( o.id, o.item, o.numStars, o.reviewer, o.comments ) FROM Rating o WHERE o.id = :id].
[93, 103] The state field path 'o.comments' cannot be resolved to a collection type. (SELECT NEW io.openliberty.jpa.data.tests.models.Rating(o.id, o.item, o.numStars, o.reviewer, [ o.comments ] ...
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildException(HermesParser.java:175)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.validate(HermesParser.java:364)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.populateQueryImp(HermesParser.java:298)
at org.eclipse.persistence.internal.jpa.jpql.HermesParser.buildQuery(HermesParser.java:180)
I would have expected EclipseLink to be able to satisfy this JPQL query with a SQL Query something like:
SELECTt0.ID, t0.NAME, t0.PRICE, t0.NUMSTARS, t0.EMAIL, t0.FIRSTNAME, t0.LASTNAME, t1.COMMENTSFROM RATING t0
LEFT OUTER JOIN Rating_COMMENTS t1
ON (t1.Rating_ID=t0.ID)
WHERE (t0.ID= ?)
The text was updated successfully, but these errors were encountered:
KyleAure
changed the title
JPQL SELECT NEW not joining or recogning ElementCollection
JPQL SELECT NEW not joining nor recogning ElementCollection as a collection type
Aug 23, 2024
KyleAure
added a commit
to KyleAure/open-liberty
that referenced
this issue
Aug 23, 2024
EclipseLink is rejecting JPQL SELECT NEW clauses where an entity contains an attribute that is an ElementCollection.
For example,
SELECT o.comments FROM Rating o WHERE o.id = :id
where the columncomments
is an ElementCollection is correctly returned as a result set.We can see from the SQL generated by EclipseLink that a JOIN is required to get the data from the
Rating_COMMENTS
table:However, when we try to use
o.comments
in aSELECT NEW
query like the one below:The following error is thrown:
I would have expected EclipseLink to be able to satisfy this JPQL query with a SQL Query something like:
The text was updated successfully, but these errors were encountered: