Summary
Switching the order of two elements in a List throws an exception. This code was previously working but now throws an exception since upgrading to DN-rdbms with the bulk shift optimization:
List<CompositeObject> childObjects = a.getChildObjects();
int idx = 10;
childObjects.add(idx - 1, childObjects.remove(idx));
This issue can be reproduced with a single class via the attached testcase. A bug appears to be introduced to DN since the bulk shift optimization was implemented to improve the performance of element reordering in 1-m relationships. Code that has been working for many years started raising this exception after we upgraded to dn-rdbms version: 5.2.12.
Outline of the bug and testcase
- A CompositeObject class exists with a 1-m relationship (Join table) as List of elements which are also of type CompositeObject
- A top level object is created and then a number of child elements are added to it.
- In a subsequent transaction one of the items is removed from its position and re-added to the position above where it was previously - i.e. attempting to switch positions with the item above it.
This results in a BatchUpdateException: INSERT INTO failure with details: Duplicate entry '1-10' for key 'composite_childobjects.PRIMARY'
It works fine on H2 (and maybe other DBs?) but fails on MySQL for some reason - for this reason the test case must use MySQL 8+
The testcase assumes a MySQL DB at localhost with a database called dntest with username: dntest and password: dntest
Environment
OS: both Windows + Linux
dn-core version: 5.2.11
dn-rdbms version: 5.2.12
mysql versions tested so far: 8.0.28, 8.0.32
Testcase
reorderingElementsInJoinTable1mImpl.zip
Summary
Switching the order of two elements in a List throws an exception. This code was previously working but now throws an exception since upgrading to DN-rdbms with the bulk shift optimization:
This issue can be reproduced with a single class via the attached testcase. A bug appears to be introduced to DN since the bulk shift optimization was implemented to improve the performance of element reordering in 1-m relationships. Code that has been working for many years started raising this exception after we upgraded to dn-rdbms version: 5.2.12.
Outline of the bug and testcase
This results in a BatchUpdateException: INSERT INTO failure with details: Duplicate entry '1-10' for key 'composite_childobjects.PRIMARY'
It works fine on H2 (and maybe other DBs?) but fails on MySQL for some reason - for this reason the test case must use MySQL 8+
The testcase assumes a MySQL DB at localhost with a database called dntest with username: dntest and password: dntest
Environment
OS: both Windows + Linux
dn-core version: 5.2.11
dn-rdbms version: 5.2.12
mysql versions tested so far: 8.0.28, 8.0.32
Testcase
reorderingElementsInJoinTable1mImpl.zip