mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1247 - Unique index or primary key violation - when jdbc batch cascading to PrivateOwned child with unique constraint
This commit is contained in:
@@ -84,6 +84,10 @@ public class BatchedBeanHolder {
|
||||
// with binding addBatch() for each request.
|
||||
// Note updates and deletes can result in many PreparedStatements
|
||||
// if their where clauses differ via use of IS NOT NULL.
|
||||
if (deletes != null && !deletes.isEmpty()) {
|
||||
control.executeNow(deletes);
|
||||
deletes.clear();
|
||||
}
|
||||
if (inserts != null && !inserts.isEmpty()) {
|
||||
control.executeNow(inserts);
|
||||
inserts.clear();
|
||||
@@ -92,10 +96,6 @@ public class BatchedBeanHolder {
|
||||
control.executeNow(updates);
|
||||
updates.clear();
|
||||
}
|
||||
if (deletes != null && !deletes.isEmpty()) {
|
||||
control.executeNow(deletes);
|
||||
deletes.clear();
|
||||
}
|
||||
persistedBeans.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.tests.cascade;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.TSDetail;
|
||||
import org.tests.model.basic.TSMaster;
|
||||
@@ -27,4 +28,30 @@ public class TestPrivateOwnedCascadeOrder extends BaseTestCase {
|
||||
|
||||
Ebean.save(master1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithTransaction() {
|
||||
|
||||
// setup
|
||||
TSMaster master = new TSMaster();
|
||||
master.getDetails().add(new TSDetail("d97", "ONE2"));
|
||||
master.getDetails().add(new TSDetail("d96", "TWO2"));
|
||||
|
||||
Ebean.save(master);
|
||||
|
||||
// act
|
||||
TSMaster master1 = Ebean.find(master.getClass(), master.getId());
|
||||
|
||||
// Check Ebean deletes the existing c97 first as the unique values clash
|
||||
Transaction transaction = Ebean.beginTransaction();
|
||||
try {
|
||||
master1.getDetails().clear();
|
||||
master1.getDetails().add(new TSDetail("d98", "TWO2"));
|
||||
|
||||
Ebean.save(master1);
|
||||
transaction.commit();
|
||||
} finally {
|
||||
transaction.end();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user