Home » Eclipse Projects » EclipseLink » (Resolved) EclipseLink 2.6.0 creates too many instances when join fetching ElementCollection(Too many instances returned from query.getResultList() when JP QL query join fetches an ElementCollection type instance variable)
|(Resolved) EclipseLink 2.6.0 creates too many instances when join fetching ElementCollection [message #1718923]
||Sat, 02 January 2016 16:57
| Doug Gschwind
Registered: April 2012
I am using EclipseLink 2.6.0, Java 8, and a JP QL NamedQuery to find all instances of a certain class (I will describe my entities shortly) that reside in my MySQL 5.6 database. I am expecting to get three instances of this class when the query is executed, but I instead get thousands. This certain class has an ElementCollection that houses Set<Integer> that is marked to be lazily loaded. Across these three instances that I expect to find, there are some 44,000 or so Integers held in the ElementCollection instance variables for those three instances, and it appears that when the query executes, instead of getting just three instances back, it appears I am getting 44,000 back.
Ok, let me describe the JPA entities involved here. The EOS class has an ElementCollection that is of type Set<Integer>, accountIds, and that relationship is marked as FetchType.LAZY. EOS also has a ManyToOne to EO, EO has a ManyToOne to O, and O has a ManyToOne to OF. All these relationships are marked as FetchType.LAZY.
The JP QL query I have written looks like the following and I have implemented it as a NamedQuery
select eos from EOS eos join fetch eos.accountIds join eos.eo eo where eo.x = and eo.o.of.id = :id
I have further attempted to use distinct in the above query, but even with with following form of the query, I still get many, many more instances of the EOS class than I am expecting, I am only expecting to find three instances :
select distinct eos from EOS eos join fetch eos.accountIds join eos.eo eo where eo.x = and eo.o.of.id = :id
As at least a temporary workaround, the List<EOS> that is returned to me from query.getResultList(), I simply pass into the constructor of a HashSet<EOS> and that then eliminates the duplicates and I then finally just have the three instances that I seek. It seems like the second form of the query should do the job, but does not.
I have reviewed the defects fixed in EclipseLInk 2.6.1 and 2.6.2 and this problem I am experiencing doesn't appear to be listed in those addressed with either release.
Thus, I am wondering if anyone here knows if this is a JPA limitation with use of ElementCollection, if my query is still naively constructed in some way, if this may in fact be a defect with EclipseLink 2.6.0, or this problem is due to something else entirely?
[Updated on: Sat, 09 January 2016 04:44]
Report message to a moderator
Current Time: Thu Mar 04 01:13:45 GMT 2021
Powered by FUDForum
. Page generated in 0.01569 seconds