Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPQL SELECT NEW not joining nor recognising ElementCollection as a collection type #2264

Open
Riva-Tholoor-Philip opened this issue Sep 13, 2024 · 0 comments

Comments

@Riva-Tholoor-Philip
Copy link
Contributor

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:

SELECT t1.COMMENTS 
FROM 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 
WHERE o.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:

SELECT t0.ID, t0.NAME, t0.PRICE, t0.NUMSTARS, t0.EMAIL, t0.FIRSTNAME, t0.LASTNAME, t1.COMMENTS 
FROM RATING t0
  LEFT OUTER JOIN Rating_COMMENTS t1 
  ON (t1.Rating_ID = t0.ID) 
WHERE (t0ID = ?)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant