Issue Details (XML | Word | Printable)

Key: NUCRDBMS-403
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Areg Beketovski
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
DataNucleus Store RDBMS

Map.put() fails producing incorrect SELECT query

Created: 31/May/10 09:15 PM   Updated: 11/Jun/10 01:38 PM   Resolved: 01/Jun/10 01:32 PM
Component/s: Queries
Affects Version/s: 2.1.0.m3
Fix Version/s: 2.1.0.release

File Attachments: 1. Zip Archive testcase.zip (4 kB)


Datastore: H2, Microsoft SQL Server, MySQL


 Description  « Hide
In case of 5 level deep inheritance (E extends D ... B extends A) when trying to put a "new C()" into a persisted "Map<Integer, C>" field, a query with duplicate aliases is generated:

----
SELECT 'org.datanucleus.test.C' AS NUCLEUS_TYPE,`A3`.`F`,`A4`.`DF`,`A1`.`C_ID`,`A1`.`DISCRIMINATOR` FROM `M_MAP` `A0` INNER JOIN `C` `A1` ON `A0`.`C_ID_VID` = `A1`.`C_ID` LEFT OUTER JOIN `D` `A2` ON `A0`.`C_ID_VID` = `A2`.`D_ID` INNER JOIN `A` `A3` ON `A1`.`C_ID` = `A3`.`A_ID` INNER JOIN `B` `A4` ON `A1`.`C_ID` = `A4`.`B_ID` WHERE `A1`.`DISCRIMINATOR` = 'org.datanucleus.test.C' AND `A2`.`D_ID` IS NULL AND `A0`.`M_ID_OID` = ? AND `A0`.`KEY` = ?
UNION SELECT 'org.datanucleus.test.E' AS NUCLEUS_TYPE,`A3`.`F`,`A4`.`DF`,`A1`.`C_ID`,`A1`.`DISCRIMINATOR` FROM `M_MAP` `A0` INNER JOIN `C` `A1` ON `A0`.`C_ID_VID` = `A1`.`C_ID` INNER JOIN `E` `A2` ON `A1`.`C_ID` = `A2`.`E_ID` INNER JOIN `A` `A3` ON `A1`.`C_ID` = `A3`.`A_ID` INNER JOIN `B` `A4` ON `A1`.`C_ID` = `A4`.`B_ID` WHERE `A0`.`M_ID_OID` = ? AND `A0`.`KEY` = ?
UNION SELECT 'org.datanucleus.test.D' AS NUCLEUS_TYPE,`A3`.`F`,`A4`.`DF`,`A1`.`C_ID`,`A1`.`DISCRIMINATOR` FROM `M_MAP` `A0` INNER JOIN `C` `A1` ON `A0`.`C_ID_VID` = `A1`.`C_ID` INNER JOIN `D` `A2` ON `A1`.`C_ID` = `A2`.`D_ID` LEFT OUTER JOIN `E` `A3` ON `A0`.`C_ID_VID` = `A3`.`E_ID`
/* --> Duplicate alias "A3" <-- */
INNER JOIN `A` `A3` ON `A1`.`C_ID` = `A3`.`A_ID` INNER JOIN `B` `A4` ON `A1`.`C_ID` = `A4`.`B_ID`
WHERE `A2`.`DISCRIMINATOR` = 'org.datanucleus.test.D' AND `A3`.`E_ID` IS NULL AND `A0`.`M_ID_OID` = ? AND `A0`.`KEY` = ?
----

Also when setting "@Inheritance(strategy = InheritanceStrategy.SUPERCLASS_TABLE)" on D a slightly different but again incorrect query is generated:

----
SELECT 'org.datanucleus.test.C' AS NUCLEUS_TYPE,`A2`.`F`,`A3`.`DF`,`A1`.`C_ID`,`A1`.`DISCRIMINATOR` FROM `M_MAP` `A0` INNER JOIN `C` `A1` ON `A0`.`C_ID_VID` = `A1`.`C_ID` INNER JOIN `A` `A2` ON `A1`.`C_ID` = `A2`.`A_ID` INNER JOIN `B` `A3` ON `A1`.`C_ID` = `A3`.`B_ID` WHERE `A1`.`DISCRIMINATOR` = 'org.datanucleus.test.C' AND `A0`.`M_ID_OID` = ? AND `A0`.`KEY` = ?
UNION SELECT 'org.datanucleus.test.E' AS NUCLEUS_TYPE,`A2`.`F`,`A3`.`DF`,`A1`.`C_ID`,`A1`.`DISCRIMINATOR` FROM `M_MAP` `A0` INNER JOIN `C` `A1` ON `A0`.`C_ID_VID` = `A1`.`C_ID` INNER JOIN `E` `A2` ON `A1`.`C_ID` = `A2`.`E_ID`
/* --> Duplicate alias "A2" <-- */
INNER JOIN `A` `A2` ON `A1`.`C_ID` = `A2`.`A_ID` INNER JOIN `B` `A3` ON `A1`.`C_ID` = `A3`.`B_ID` WHERE `A0`.`M_ID_OID` = ? AND `A0`.`KEY` = ?
UNION SELECT 'org.datanucleus.test.D' AS NUCLEUS_TYPE,`A2`.`F`,`A3`.`DF`,`A1`.`C_ID`,`A1`.`DISCRIMINATOR` FROM `M_MAP` `A0` INNER JOIN `C` `A1` ON `A0`.`C_ID_VID` = `A1`.`C_ID` LEFT OUTER JOIN `E` `A2` ON `A0`.`C_ID_VID` = `A2`.`E_ID` INNER JOIN `A` `A2` ON `A1`.`C_ID` = `A2`.`A_ID` INNER JOIN `B` `A3` ON `A1`.`C_ID` = `A3`.`B_ID` WHERE `A1`.`DISCRIMINATOR` = 'org.datanucleus.test.D' AND `A2`.`E_ID` IS NULL AND `A0`.`M_ID_OID` = ? AND `A0`.`KEY` = ?
----


Please see attached testcase.

Areg Beketovski made changes - 31/May/10 09:16 PM
Field Original Value New Value
Attachment testcase.zip [ 11190 ]
Areg Beketovski added a comment - 01/Jun/10 12:56 PM
Trunk version fixes the issue. Thanks a lot, Andy!

Andy Jefferson made changes - 01/Jun/10 01:32 PM
Status Open [ 1 ] Resolved [ 5 ]
Fix Version/s 2.1.0.release [ 10832 ]
Resolution Fixed [ 1 ]
Andy Jefferson made changes - 11/Jun/10 01:38 PM
Status Resolved [ 5 ] Closed [ 6 ]