#1472 - Cascade insert with managed id ... results in update rather than insert statement

This commit is contained in:
rob bygrave
2018-08-15 23:12:06 +12:00
parent 340b100a1a
commit 29c5a17202
5 changed files with 132 additions and 34 deletions
@@ -12,10 +12,37 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestOneToOneOrphanStringId extends BaseTestCase {
@Test
public void test() {
public void test_updateInsert() {
OtoAtwo b = new OtoAtwo("b1", "b test");
Ebean.save(b);
OtoAone a = new OtoAone("a1", "a test");
b.setAone(a);
LoggedSqlCollector.start();
Ebean.save(b);
List<String> update = LoggedSqlCollector.current();
assertThat(update).hasSize(2);
assertThat(update.get(0)).contains("insert into oto_aone");
assertThat(update.get(1)).contains("update oto_atwo set aone_id=? where id=?");
Ebean.delete(b);
List<String> deletes = LoggedSqlCollector.stop();
assertThat(deletes).hasSize(2);
assertThat(deletes.get(0)).contains("delete from oto_atwo");
assertThat(deletes.get(1)).contains("delete from oto_aone");
}
@Test
public void test_cascade() {
OtoAone a = new OtoAone("a2", "a test");
OtoAtwo b = new OtoAtwo("b2", "b test");
OtoAone a = new OtoAone("a", "a test");
OtoAtwo b = new OtoAtwo("b", "b test");
b.setAone(a);
LoggedSqlCollector.start();