Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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 Go to next message
Doug Gschwind is currently offline Doug GschwindFriend
Messages: 17
Registered: April 2012
Junior Member
Hello everyone,

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 = Mad 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 = Mad 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?

Thanks, Doug

[Updated on: Sat, 09 January 2016 04:44]

Report message to a moderator

Re: EclipseLink 2.6.0 creates too many instances when join fetching ElementCollection [message #1719038 is a reply to message #1718923] Mon, 04 January 2016 16:12 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
I would expect the extra results unless the 'distinct' keyword is there and though I have not looked through the bug database, I was not aware of any issues with the distinct filtering. While it doesn't hurt to try the latest EclipseLink version, it seems like a bug to be filed if it isn't there already.

If it isn't filed already, try to narrow down what is involved in the issue:
1) does the issue occur with 'join fetch eos.accountIds' removed from the query, could it be related to the 'join eos.eo eo' portion?
2) When you add in the distinct key word, how many instances of each entity are returned, and which join would this related to?
3) Are there any annotations/options being used within the entity that might affect the count?
4) How many instances do you get with just a eo.id=:id type query? Do the above mentioned joins change this?

I would recommend using a batch query for the element collection data; while it adds an additional query, it doesn't mess up counts and would work around this issue as well.

Best Regards,
Chris

Re: EclipseLink 2.6.0 creates too many instances when join fetching ElementCollection [message #1719573 is a reply to message #1718923] Sat, 09 January 2016 04:30 Go to previous messageGo to next message
Doug Gschwind is currently offline Doug GschwindFriend
Messages: 17
Registered: April 2012
Junior Member
After further diagnosis of this issue in preparation to answer Chris' response, I found that while my debugger indicates there is duplication of EOS instances, there are actually not. I am only expecting to have 3 elements in the List<EOS> returned from .getResultList(), and that is indeed all that are being returned. Of course, my JP QL query does need to be of the form "select distinct eos from ....".

So, there is no issue here other than my failure to complete an accurate analysis.
Re: EclipseLink 2.6.0 creates too many instances when join fetching ElementCollection [message #1719574 is a reply to message #1719038] Sat, 09 January 2016 04:33 Go to previous message
Doug Gschwind is currently offline Doug GschwindFriend
Messages: 17
Registered: April 2012
Junior Member
Sorry for the delay Chris, took me a while to be able to circle back to this. Thanks for chiming in.

Please see my response, as the List<EOS> returned from query.getResultList() was in fact only returning 3 instances even though what I was seeing in my debugger indicated there were many more than that.
Previous Topic:Integrate BoneCP and EclipseLink with LOCAL_RESOURCE transaction-type
Next Topic:Recommended Java version
Goto Forum:
  


Current Time: Fri Mar 29 10:59:04 GMT 2024

Powered by FUDForum. Page generated in 0.03069 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top