#1606 - Bean with Inheritance and OneToMany with JoinTable and cascade ... doesn't cascade save on all bean types

This commit is contained in:
rob bygrave
2019-01-09 12:29:28 +13:00
parent 5e22079366
commit 8544712448
5 changed files with 98 additions and 0 deletions
@@ -0,0 +1,55 @@
package org.tests.o2m.jointable;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import org.tests.o2m.jointable.inheritance.ClassA;
import org.tests.o2m.jointable.inheritance.ClassB;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestOneToManyJoinTableInheritance extends BaseTestCase {
private JtMonkey m0 = new JtMonkey("Sim");
private JtMonkey m1 = new JtMonkey("Tim");
private JtMonkey m2 = new JtMonkey("Uim");
private ClassA classA = new ClassA();
private ClassB classB = new ClassB();
@Test
public void testSave() {
classA.getMonkeys().add(m0);
classA.getMonkeys().add(m1);
classB.getMonkeys().add(m2);
LoggedSqlCollector.start();
Ebean.saveAll(Arrays.asList(classA, classB));
List<String> sql = LoggedSqlCollector.current();
assertThat(sql).hasSize(7);
assertThat(sql.get(0)).contains("insert into class_super ");
assertThat(sql.get(1)).contains("insert into monkey ");
assertThat(sql.get(2)).contains("insert into monkey ");
assertThat(sql.get(3)).contains("insert into class_super_monkey ");
assertThat(sql.get(4)).contains("insert into class_super ");
assertThat(sql.get(5)).contains("insert into monkey ");
assertThat(sql.get(6)).contains("insert into class_super_monkey ");
ClassA dbA = Ebean.find(ClassA.class, 1);
ClassB dbB = Ebean.find(ClassB.class, 2);
assertThat(dbA.getMonkeys()).hasSize(2);
assertThat(dbB.getMonkeys()).hasSize(1);
assertThat(dbA.getMonkeys().get(0).name).isEqualTo("Sim");
assertThat(dbA.getMonkeys().get(1).name).isEqualTo("Tim");
assertThat(dbB.getMonkeys().get(0).name).isEqualTo("Uim");
}
}
@@ -0,0 +1,7 @@
package org.tests.o2m.jointable.inheritance;
import javax.persistence.Entity;
@Entity
public class ClassA extends ClassSuper {
}
@@ -0,0 +1,7 @@
package org.tests.o2m.jointable.inheritance;
import javax.persistence.Entity;
@Entity
public class ClassB extends ClassSuper {
}
@@ -0,0 +1,26 @@
package org.tests.o2m.jointable.inheritance;
import org.tests.o2m.jointable.JtMonkey;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import java.util.List;
@Inheritance
@Entity
public abstract class ClassSuper {
@Id
long sid;
@JoinTable
@OneToMany(cascade = CascadeType.ALL)
private List<JtMonkey> monkeys;
public List<JtMonkey> getMonkeys() {
return monkeys;
}
}