fix if managed bean is removed and added in same step

This commit is contained in:
Roland Praml
2022-08-12 10:55:13 +02:00
parent a41cbea48c
commit 2e24126561
2 changed files with 12 additions and 1 deletions
@@ -307,6 +307,7 @@ final class SaveManyBeans extends SaveManyBase {
}
transaction.depth(+1);
boolean needsFlush = false;
if (deletions != null && !deletions.isEmpty()) {
for (Object other : deletions) {
EntityBean otherDelete = (EntityBean) other;
@@ -315,6 +316,7 @@ final class SaveManyBeans extends SaveManyBase {
IntersectionRow intRow = many.buildManyToManyMapBean(parentBean, otherDelete, publish);
SpiSqlUpdate sqlDelete = intRow.createDelete(server, DeleteMode.HARD, many.extraWhere());
persister.executeOrQueue(sqlDelete, transaction, queue);
needsFlush = true;
}
}
if (additions != null && !additions.isEmpty()) {
@@ -334,6 +336,9 @@ final class SaveManyBeans extends SaveManyBase {
// build a intersection bean for 'insert'
// They need to be executed very late and would normally go to Queue#2, but we do not have
// a SpiSqlUpdate for now.
if (needsFlush) {
transaction.flushBatchOnCascade();
}
if (queue) {
transaction.depth(+100);
}
@@ -19,7 +19,7 @@ public class TestM2MWithWhere extends BaseTestCase {
@Test
public void testModify() throws Exception {
MnyNode node1 = new MnyNode();
node1.setName("node1");
node1.setId(111);
@@ -52,6 +52,12 @@ public class TestM2MWithWhere extends BaseTestCase {
DB.refresh(node2);
assertThat(node2.getAllRelations()).containsExactlyInAnyOrder(node3);
node2.getAllRelations().clear();
node2.getAllRelations().add(node3);
LoggedSql.start();
DB.save(node2);
LoggedSql.stop().forEach(System.out::println);
}
@Test