Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 307497 - Query populates attributes with wrong select list items of the query result.
Summary: Query populates attributes with wrong select list items of the query result.
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard: submitted_patch
Keywords:
Depends on:
Blocks:
 
Reported: 2010-03-30 04:57 EDT by Vikram Bhatia CLA
Modified: 2022-06-09 10:22 EDT (History)
5 users (show)

See Also:


Attachments
Testcase Newly added files (13.14 KB, application/zip)
2010-03-30 05:06 EDT, Vikram Bhatia CLA
no flags Details
Changes for Testcase to be integrated into EclipseLink to run it from test-browser (3.68 KB, application/octet-stream)
2010-03-30 05:08 EDT, Vikram Bhatia CLA
no flags Details
Patch to fix the issue (2.81 KB, patch)
2010-03-30 05:09 EDT, Vikram Bhatia CLA
no flags Details | Diff
Fix Version 2 (1.55 KB, patch)
2010-04-01 08:04 EDT, Vikram Bhatia CLA
no flags Details | Diff
Patch Version 3 (4.07 KB, patch)
2010-05-11 11:07 EDT, Vikram Bhatia CLA
no flags Details | Diff
Testcase Newly Added Files. (13.64 KB, patch)
2010-05-11 11:08 EDT, Vikram Bhatia CLA
no flags Details | Diff
Patch including testcase changes. (41.10 KB, patch)
2010-05-11 12:02 EDT, Vikram Bhatia CLA
no flags Details | Diff
Final Patch with few changes as per process. (39.81 KB, patch)
2010-05-13 01:52 EDT, Vikram Bhatia CLA
david.minsky: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Vikram Bhatia CLA 2010-03-30 04:57:15 EDT
Build Identifier: 1.1.1

Query with multiple addJoinedAttributes on attributes of same type populates
attributes with values of the wrong select list items.

  ReadAllQuery query = new ReadAllQuery();
  query.setReferenceClass(CarOwner.class);
  Expression rootExpression = query.getExpressionBuilder();

  // Without this expression ist works.
  Expression expression = rootExpression.getAllowingNull("car");
  query.addJoinedAttribute(expression);
  expression = expression.getAllowingNull("engineType");
  query.addJoinedAttribute(expression);

  expression = rootExpression.getAllowingNull("lastCar");
  query.addJoinedAttribute(expression);
  expression = expression.get("fuelType");
  query.addJoinedAttribute(expression);

  expression = rootExpression.getAllowingNull("car");
  query.addJoinedAttribute(expression);
  expression = expression.get("fuelType");
  query.addJoinedAttribute(expression);

  List<Person> result = (List<Person>) session.executeQuery(query);
  assertEquals("Incorrect result set size.", 1, result.size());
  CarOwner person = result.get(0);
  assertEquals("Diesel", person.getLastCar().getFuelType().getDescription());
  assertEquals("Petrol", person.getCar().getFuelType().getDescription());


Reproducible: Always

Steps to Reproduce:
Port the enclosed testcase in EclipseLink under foundation/eclipselink.core.test, and run it using test-browser under FeatureTestModel -> ExpressionSubSelectTestSuite -> MultipleJoinedAttributeOrderExpressionTest.
Comment 1 Vikram Bhatia CLA 2010-03-30 05:06:15 EDT
Created attachment 163382 [details]
Testcase Newly added files

Unzip the contents to main/trunk folder for all the newly added files to reproduce the issue.
Comment 2 Vikram Bhatia CLA 2010-03-30 05:08:10 EDT
Created attachment 163383 [details]
Changes for Testcase to be integrated into EclipseLink to run it from test-browser

This needs to be merged to reproduce the issue using test-browser.
Comment 3 Vikram Bhatia CLA 2010-03-30 05:09:16 EDT
Created attachment 163384 [details]
Patch to fix the issue

Patch to fix the issue.
Comment 4 Vikram Bhatia CLA 2010-03-30 05:13:05 EDT
To reproduce the issue:
1. Unzip the contents of attachment # 163382 [details] to the trunk folder.
2. Merge the attachment # 163383 [details] to the foundation/eclipselink.core.test.
3. Build & Run the testcase using test-browser under the following

LRGTestSuite -> FeatureTestModel -> ExpressionSubSelectTestSuite ->
MultipleJoinedAttributeOrderExpressionTest.
Comment 5 Vikram Bhatia CLA 2010-03-30 05:16:39 EDT
There are some assumptions made about ordering in EclipseLink code.

When a query with joined attributes is executed we have to compute the
indexes in the result set where the data corresponding to various objects
exists.

This is done in a method called:
joinedAttributeManager.computeIndexesForJoinedExpressions()

This method is designed to assume that any nested joins will be grouped
together. So, in order to fix this issue is likely to have some code that executes before the above method that groups all the joined attributes with the same first join together in the list.
Comment 6 Gordon Yorke CLA 2010-03-30 09:53:54 EDT
What happens if you do not add the join for "car" and "fuel-type" twice?
Comment 7 Vikram Bhatia CLA 2010-03-31 02:42:42 EDT
It works as expected if one removes the second join for "car" and "fuel-type". 

car -> engineType
lastCar -> fuelType

If one also rewrites this, i.e., grouping all "car" joins together, it again works as expected. 

car -> engineType
car -> fuelType
lastCar -> fuelType


This issue can only be reproduced if one add the joins in the following order.

car -> engineType
lastCar -> fuelType
car -> fuelType

It is even difficult to find what is wrong since it fires same SQL query for both use cases above, but java objects are initialized with incorrect values.

Since, eclipselink is expecting the nested joins to be grouped together, it can rearrange the joined attributes internally which will eventually resolve this issue rather than relying on the user to group them together while adding joined attributes to the query.
Comment 8 Vikram Bhatia CLA 2010-03-31 02:47:49 EDT
With the enclosed test case

Java objects are initialized with following values.

Car.FuelType -> Diesel.
LastCar.FuelType -> Diesel.

However, the correct values need to be

Car.FuelType -> Petrol.
LastCar.FuelType -> Diesel.
Comment 9 Gordon Yorke CLA 2010-03-31 09:36:54 EDT
> If one also rewrites this, i.e., grouping all "car" joins together, it again
> works as expected. 
> 
> car -> engineType
> car -> fuelType
> lastCar -> fuelType
> 

So the issue is that the expression joining to 'car' is added twice.  A better solution would be to group expressions as they are added to the query (perhaps even raising an exception)
Comment 10 Vikram Bhatia CLA 2010-04-01 08:04:24 EDT
Created attachment 163626 [details]
Fix Version 2

Good suggestion. I have made the changes and proposed another fix making changes while adding the joined attribute expressions to the JoinedAttributeManager.
Comment 11 Tom Ware CLA 2010-04-08 10:28:27 EDT
Setting target and priority.  See the following page for details of the
meanings of these fields:

http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Comment 12 Vikram Bhatia CLA 2010-05-11 11:07:28 EDT
Created attachment 167938 [details]
Patch Version 3
Comment 13 Vikram Bhatia CLA 2010-05-11 11:08:18 EDT
Created attachment 167939 [details]
Testcase Newly Added Files.
Comment 14 Vikram Bhatia CLA 2010-05-11 12:02:22 EDT
Created attachment 167954 [details]
Patch including testcase changes.
Comment 15 Vikram Bhatia CLA 2010-05-13 01:52:41 EDT
Created attachment 168323 [details]
Final Patch with few changes as per process.

Changed the patch as per the correct process.

1. Changed Contributor.
2. Changed directory names in diff patch, created patch from trunk instead of foundation directory.
3. Added EL Bug number with proposed fix.
Comment 16 David Minsky CLA 2010-05-13 16:28:10 EDT
Checked into trunk (r7223)
IPLog updated: http://wiki.eclipse.org/EclipseLink/IPLog#Contributions_-_2.1_Release_Log
Comment 17 Eclipse Webmaster CLA 2022-06-09 10:22:14 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink