Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 366458

Summary: Query hint eclipselink.join-fetch can cause wrongly populated data
Product: z_Archived Reporter: Anssi Törmä <anssi.torma>
Component: EclipselinkAssignee: Nobody - feel free to take it <nobody>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: P2 CC: andrei.ilitchev, eclipselink.orm-inbox, mocanushtefan, tom.ware
Version: unspecified   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
test cases
none
Test case for multiple join fetch
none
Suggested patch
none
Suggested patch + batch test none

Description Anssi Törmä CLA 2011-12-12 16:11:13 EST
Build Identifier: 2.3.2.v20111125-r10461

I have model like this: 
SignOff *-> Control <-1 Responsibility 1-> Unit

When I create an object graph where there is one SignOff related to one Control that has two Responsibilities each with a unique Unit, and execute the following query

SELECT s FROM SignOff s WHERE s.control.id = :controlId

with the following query hints

eclipselink.join-fetch = s.control
eclipselink.join-fetch = s.control.responsibilities
eclipselink.join-fetch = s.control.responsibilities.unit

then I get a Control whose both Responsibilities wrongly point to the same Unit instead of the two unique ones.

A workaround is to use only one query hint:

eclipselink.join-fetch = s.control.responsibilities.unit

but this makes me wonder if corrupted entities might be generate in other cases as well.

Reproducible: Always

Steps to Reproduce:
1. Run the provided test cases (Maven project, JUnit)
Comment 1 Anssi Törmä CLA 2011-12-12 16:12:27 EST
Created attachment 208287 [details]
test cases
Comment 2 Mocanu Stefan CLA 2011-12-13 08:36:09 EST
I encounter the same problem. It seems it might be related to applying join-fetch hints that share the beginning of the path.

I have a hierarchy like this:

A <-* B (in A I have List<B> children)
B <-* C (in B I have List<C> childrenC)
B <-* D (in B I have List<D> childrenD)

I have the query

select a from A a

Each of the following hints work separately:

qFetch.setHint(QueryHints.LEFT_FETCH, "a.children.childrenC")
qFetch.setHint(QueryHints.FETCH, "a.children.childrenD");

However, they do not work together.

I have attached a test case.
Comment 3 Mocanu Stefan CLA 2011-12-13 08:36:42 EST
Created attachment 208310 [details]
Test case for multiple join fetch
Comment 4 Mocanu Stefan CLA 2011-12-13 08:38:21 EST
I'm sorry for a small typo, both hints are QueryHints.FETCH:

qFetch.setHint(QueryHints.FETCH, "a.children.childrenC");
qFetch.setHint(QueryHints.FETCH, "a.children.childrenD");
Comment 5 Mocanu Stefan CLA 2011-12-13 09:39:07 EST
I have investigated by myself this problem, and found it to reside in JoinedAttributeManager, method prepareJoinExpressions.

There is a declaration in that method:

List groupedExpressionList = new ArrayList(getJoinedAttributeExpressions().size());

For the test case I described, there will be 4 expressions added through this line of code:

this.setJoinedAttributeExpressions_(groupedExpressionList);

The 4 expressions correspond to:

1. a.children
2. a.children.childrenC
3. a.children
4. a.children.childrenD

By hacking the "groupedExpressionList" and turning it into a Set, everything seems to work fine.

HTH
Comment 6 Tom Ware CLA 2011-12-22 10:39:09 EST
Setting target and priority.  See the following page for the meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines

Community: Please vote for this bug if it is important to you.  Votes are one of the main criteria we use to determine which bugs to fix next.
Comment 7 Andrei Ilitchev CLA 2012-05-01 16:45:30 EDT
Created attachment 214897 [details]
Suggested patch

- defined new versions of anyOf and anyOfAllowingNone methods taking boolean parameter that indicates whether to create a new expression or return existing one (the pattern of get and getAllowingNull methods);
- copied into FETCH processing ObjectAggregateMapping's handling from LEFT_FETCH.

Test: EntityManagerJUnitTestSuite.testNestedFetchQueryHints
Comment 8 Andrei Ilitchev CLA 2012-05-02 14:46:42 EDT
Created attachment 214940 [details]
Suggested patch + batch test

Added to the previous patch a new test EntityManagerJUnitTestSuite.testNestedBatchQueryHints to verify nested batching.
Comment 9 Andrei Ilitchev CLA 2012-05-02 15:16:48 EDT
Checked the patch into both trunk (2.4) and 2.3.3. Reviewed by James.
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:33:43 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink