Community
Participate
Working Groups
Created attachment 224270 [details] Maven project with JPA Model, and JUnit tests to reproduce the issue Assume I have a model with an Entity E1 with 2 onetoone on another Entity E2. E2 is an abstract class (@Inheritance) extended by 2 Entites E21 and E22. They use a discriminator column. This case is a design choice and doesn't sound too messy (to me ). When retrieving an E1 object (find by id, select in jpql or criteria), the two onetoone objects are retrieved and values of their fields are correct. As it triggers 3 sql queries, I want to optimize by join fetching the 2 onetoone : tried with jpql, criteria and JoinFetch annotation. Now one of the two retrieved E2 objects (whatever their subtypes) have incorrect fields : either the two are the same, either one of them is null. The sql generated contains distinct fields for each entity but values retrieved are badly mapped to the objects. Only workaround I see, would be to demultiply a onetoone on the abstract class to multiple onetoeones to concrete subclasses. Not really a good solution. In the attachment, I have placed a project based on maven (pom.xml). You will find : in src/main/java/, the classes of the JPA model : sample with a Customer having two addresses that can be sub-typed. In src/test/java, you will find 3 classes (DBCreateEL, InsertEL, ReadEL). In the stderr log, when launching ReadEL, you will see the values retrieved and incorrectly setted with join fetch cases (JPQL and Criteria). Find with ID / Select JPQL / NO FETCHES CRITERIA : -------------------------------------------------- The SQL : SELECT CUS_ID, CUS_ACCOUNT, ADD_ID_BA, ADD_ID_DA FROM PRO_T_CUSTOMER WHERE (CUS_ID = ?) SELECT ADD_ID, ADD_TYPE, STREET1, STREET2 FROM PRO_T_ADDRESS WHERE (ADD_ID = ?) SELECT ADD_ID, ADD_TYPE, STREET1, STREET2 FROM PRO_T_ADDRESS WHERE (ADD_ID = ?) The objects : Customer [51,ACCNUMBER, AddressType1 [streetT1], AddressType2 [streetT2]] WITH FETCHES JPQL : ------------------- The SQL : SELECT t1.CUS_ID, t1.CUS_ACCOUNT, t1.ADD_ID_BA, t1.ADD_ID_DA, t0.ADD_ID, t0.ADD_TYPE, t0.STREET1, t0.STREET2, t2.ADD_ID, t2.ADD_TYPE, t2.STREET1, t2.STREET2 FROM PRO_T_CUSTOMER t1 LEFT OUTER JOIN PRO_T_ADDRESS t0 ON (t0.ADD_ID = t1.ADD_ID_DA) LEFT OUTER JOIN PRO_T_ADDRESS t2 ON (t2.ADD_ID = t1.ADD_ID_BA) WHERE (t1.CUS_ID = ?) The objects : Customer [51,ACCNUMBER, AddressType1 [null], AddressType2 [streetT2]] WITH FETCHES CRITERIA : ----------------------- The SQL : SELECT DISTINCT t1.CUS_ID, t1.CUS_ACCOUNT, t1.ADD_ID_BA, t1.ADD_ID_DA, t0.ADD_ID, t0.ADD_TYPE, t0.STREET1, t0.STREET2, t2.ADD_ID, t2.ADD_TYPE, t2.STREET1, t2.STREET2 FROM PRO_T_CUSTOMER t1 LEFT OUTER JOIN PRO_T_ADDRESS t0 ON (t0.ADD_ID = t1.ADD_ID_BA) LEFT OUTER JOIN PRO_T_ADDRESS t2 ON (t2.ADD_ID = t1.ADD_ID_DA) WHERE (t1.CUS_ID = ?) The objects : Customer [51,ACCNUMBER, AddressType1 [streetT1], AddressType2 [null]] In the two last cases, values of addresses are incorrect. We can see that the order of join declaration affects data mapping. As we inversed the order in the two cases (I think code is clearer than me ;-) ). Note : The bug exists with 2.4.0, but I have placed the version 2.3.3 as I need a patch based on 2.3.x branch (for compatibility with toplink grid 12c).
Found an issue when looking the joinedMappingIndexes of the JoinManager (cas of the fetches with Criteria). (Used by trimRowForJoin) [null, null, org.eclipse.persistence.mappings.OneToOneMapping[billingAddress]=4, null, null, null, null, org.eclipse.persistence.mappings.OneToOneMapping[deliveryAddress]=6, null, null, null, null, null, null, null, null] The index for OneToOneMapping[deliveryAddress] should be 8 instead of 6. So fields of the billingAddress are still in the row and are used by in favour of the ones of deliveryAddress.
It seems that the compute joinedindexes doesn't take into account that the classes are extended an abstract entiy with its own fifield and in my case a discriminator column (so +2).
Created attachment 224285 [details] Quick Patch on 2.3.3 sources Attached a patch on the JoinedAttributeManager class. The computeIndexesForJoinedExpressions method only treats multitableinheritance, which in my case is not enough. I've added a simple else if, but hiding the details of the condition in the ObjectExpression like for MultiTableInheritance would be better.
The patch is compatible with 2.4.x Not tested on 2.5.x
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.
The attached Patch resolves the issue.
Why are you closing this bug? Is the patch somehow checked into the code stream?
Not at all, bug is still present and easy to fix. Wondering if status needed to be changed to indicate that the patch is ok.
We leave bugs open until the fix is checked into the appropriate EclipseLink code stream. Then we close them with the corresponding target release.
Please can you run this test with latest master branch build (2.6.0) and port this fix to master branch too? I wanted to apply your fix on master branch myself but it failed.
Created attachment 248984 [details] Test case refreshed I provide a simpler Test case, referencing the 2.6.0-M3 version of EclipseLink : Entity Customer with 2 sub entities Address (BillingAddress and DelliveryAddress). In the Junit CustomerTest, 2 tests (criteria and jpql without join fetch) succeed and 2 others fail (criteria and jpql with join fetch). Just run a "mvn test" command to view the failures.
Created attachment 248985 [details] Patch for EclipseLink 2.6.0-M3 Previous submitted patch was based on EclipseLink 2.3.3. This one is technically the same patch but realigned with sources of version 2.6.0-M3.
Created attachment 249144 [details] jUnit tests integrated into EclipseLink Here are tests integrated into JPA jUnit tests. I had to create new model under org.eclipse.persistence.testing.models.jpa.advanced.customer and rename some of the entities to get unique names. Please review my changes and let me know if you agree with pushing your original test with my modifications into EclipseLink repository.
Also, please, sign CLA and sign off your 'Patch for EclipseLink 2.6.0-M3' patch properly as described on https://wiki.eclipse.org/CLA and upload it again.
Created attachment 249169 [details] Final fix and jUnit changeset pushed into EclipseLink master Pushed into master: http://git.eclipse.org/c/eclipselink/eclipselink.runtime.git/commit/?id=65064541a4ef538059e54f28b14d5f9d75d50c25
Fis shall be available in next master nightly build.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink