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
Describe the bug
When JPQL queries select an attribute that is a ElementCollection (if using annotations) or element-collection (if using XML) and getResultList is used to obtain the result, instead of returning a List of one or more Collection(s), EclipseLink appears to be combining all of the collection values into a single list of values and returning it to the caller.
This can be surfaced to the application in a variety of ways, such as:
DataJPATestServlet.testCollectionAttribute: expected:<[507]> but was:<507>
at test.jakarta.data.jpa.web.DataJPATestServlet.testCollectionAttribute(DataJPATestServlet.java:439)
In the above case, the result list contained an Integer rather than a Set<Integer>, despite issuing a query SELECT o.areaCodes FROM City o WHERE (o.name=?1 AND o.stateName=?2) on o.areaCodes which is a collection.
Exception [EclipseLink-0] (Eclipse Persistence Services - 4.0.2.v202306161219): org.eclipse.persistence.exceptions.JPQLException
Exception Description: Problem compiling [SELECT NEW test.jakarta.data.jpa.web.AreaInfo(o.name, o.stateName, o.areaCodes) FROM City o WHERE (o.stateName=?1) ORDER BY o.name].
[67, 78] The state field path 'o.areaCodes' cannot be resolved to a collection type.
In the above case, it complains about the value being used for o.areaCodes not being a collection, when it ought to be a collection because o.areaCodes is defined as a collection on the entity.
Steps to Reproduce
This fails a variety of test cases so there are various places where you can reproduce it.
One way: uncomment the line @ElementCollection(fetch = FetchType.EAGER) on test.jakarta.data.jpa.web.City and run the io.openliberty.data.internal_fat_jpa test bucket. The test testCollectionAttribute will start failing.
Another way: uncomment the lines of testRecordWithEmbeddables in test.jakarta.data.web.DataTestServlet and run the io.openliberty.data.internal_fat test bucket.
Another way: uncomment the lines of testEmbeddableCollection in test.jakarta.data.jpa.web.DataJPATestServlet and run the io.openliberty.data.internal_fat_jpa test bucket.
Expected behavior
JPQL queries for an attribute that is a Set<Integer> should return a result list that contains Set<Integer>, not Integer.
JPQL queries that construct a new class instance with an attribute that is a Set<Integer> as a parameter should receive a Set<Integer> and successfully construct an instance, not be rejected saying that the collection attribute is not a collection attribute.
Diagnostic information:
OpenLiberty Version: latest
Affected feature(s) persistence-3.1
Java Version:
java.home = /Users/njr/drivers/jdk-21.jdk/Contents/Home
java.version = 21
java.runtime = OpenJDK Runtime Environment (21+35-2513)
os = Mac OS X (14.5; aarch64) (en_US)
server.xml configuration (WITHOUT sensitive information like passwords) see test buckets
The text was updated successfully, but these errors were encountered:
@Entity
@IdClass(CityId.class)
public class City {
@ElementCollection(fetch = FetchType.EAGER)
public Set<Integer> areaCodes;
@Version
long changeCount;
@Id
public String name;
public int population;
@Id
public String stateName;
public static City of(String name, String state, int population, Set<Integer> areaCodes) {
City inst = new City();
inst.name = name;
inst.stateName = state;
inst.population = population;
inst.areaCodes = areaCodes;
return inst;
}
@Override
public String toString() {
return "City of " + name + ", " + stateName + " pop " + population + " in " + areaCodes + " v" + changeCount;
}
}
Describe the bug
When JPQL queries select an attribute that is a
ElementCollection
(if using annotations) orelement-collection
(if using XML) and getResultList is used to obtain the result, instead of returning a List of one or more Collection(s), EclipseLink appears to be combining all of the collection values into a single list of values and returning it to the caller.This can be surfaced to the application in a variety of ways, such as:
In the above case, the result list contained an
Integer
rather than aSet<Integer>
, despite issuing a querySELECT o.areaCodes FROM City o WHERE (o.name=?1 AND o.stateName=?2)
ono.areaCodes
which is a collection.In the above case, it complains about the value being used for
o.areaCodes
not being a collection, when it ought to be a collection becauseo.areaCodes
is defined as a collection on the entity.Steps to Reproduce
This fails a variety of test cases so there are various places where you can reproduce it.
One way: uncomment the line
@ElementCollection(fetch = FetchType.EAGER)
on test.jakarta.data.jpa.web.City and run the io.openliberty.data.internal_fat_jpa test bucket. The testtestCollectionAttribute
will start failing.Another way: uncomment the lines of
testRecordWithEmbeddables
in test.jakarta.data.web.DataTestServlet and run the io.openliberty.data.internal_fat test bucket.Another way: uncomment the lines of
testEmbeddableCollection
in test.jakarta.data.jpa.web.DataJPATestServlet and run the io.openliberty.data.internal_fat_jpa test bucket.Expected behavior
JPQL queries for an attribute that is a
Set<Integer>
should return a result list that containsSet<Integer>
, not Integer.JPQL queries that construct a new class instance with an attribute that is a
Set<Integer>
as a parameter should receive aSet<Integer>
and successfully construct an instance, not be rejected saying that the collection attribute is not a collection attribute.Diagnostic information:
server.xml configuration (WITHOUT sensitive information like passwords) see test buckets
The text was updated successfully, but these errors were encountered: