Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 366458 - Query hint eclipselink.join-fetch can cause wrongly populated data
Summary: Query hint eclipselink.join-fetch can cause wrongly populated data
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 7
: P2 normal with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-12 16:11 EST by Anssi Törmä CLA
Modified: 2022-06-09 10:33 EDT (History)
4 users (show)

See Also:


Attachments
test cases (9.17 KB, application/zip)
2011-12-12 16:12 EST, Anssi Törmä CLA
no flags Details
Test case for multiple join fetch (3.43 KB, application/zip)
2011-12-13 08:36 EST, Mocanu Stefan CLA
no flags Details
Suggested patch (17.13 KB, patch)
2012-05-01 16:45 EDT, Andrei Ilitchev CLA
no flags Details | Diff
Suggested patch + batch test (25.72 KB, patch)
2012-05-02 14:46 EDT, Andrei Ilitchev CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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