Community
Participate
Working Groups
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.
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.
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.
Created attachment 163384 [details] Patch to fix the issue Patch to fix the issue.
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.
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.
What happens if you do not add the join for "car" and "fuel-type" twice?
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.
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.
> 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)
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.
Setting target and priority. See the following page for details of the meanings of these fields: http://wiki.eclipse.org/EclipseLink/Development/Bugs/Guidelines
Created attachment 167938 [details] Patch Version 3
Created attachment 167939 [details] Testcase Newly Added Files.
Created attachment 167954 [details] Patch including testcase changes.
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.
Checked into trunk (r7223) IPLog updated: http://wiki.eclipse.org/EclipseLink/IPLog#Contributions_-_2.1_Release_Log
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink