diff --git a/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java b/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java index 749d597f1..e9252c819 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java +++ b/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInherit.java @@ -128,7 +128,7 @@ public class DeployInherit { if (dv != null) { info.setDiscriminatorValue(dv.value()); } else { - info.setDiscriminatorValue(cls.getSimpleName()); + info.setDiscriminatorDefaultValue(cls); } } return info; diff --git a/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java b/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java index 60e1d353c..fb1a65a54 100644 --- a/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java +++ b/src/main/java/io/ebeaninternal/server/deploy/parse/DeployInheritInfo.java @@ -178,6 +178,16 @@ public class DeployInheritInfo { return discriminatorStringValue; } + public void setDiscriminatorDefaultValue(Class cls) { + if (columnType == Types.INTEGER) { + discriminatorStringValue = "0"; + discriminatorObjectValue = 0; + } else { + discriminatorStringValue = cls.getSimpleName(); + discriminatorObjectValue = discriminatorStringValue; + } + } + /** * Set the discriminator value for this node. */ diff --git a/src/test/java/org/tests/inherit/DIntChild1.java b/src/test/java/org/tests/inherit/DIntChild1.java new file mode 100644 index 000000000..a76c0f272 --- /dev/null +++ b/src/test/java/org/tests/inherit/DIntChild1.java @@ -0,0 +1,19 @@ +package org.tests.inherit; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity +@DiscriminatorValue("1") +public class DIntChild1 extends DIntChildBase { + + @Override + public String getName() { + return "A Name"; + } + + public DIntChild1(Integer number, String more) { + super(number, more); + } + +} diff --git a/src/test/java/org/tests/inherit/DIntChild2.java b/src/test/java/org/tests/inherit/DIntChild2.java new file mode 100644 index 000000000..5f3737c90 --- /dev/null +++ b/src/test/java/org/tests/inherit/DIntChild2.java @@ -0,0 +1,19 @@ +package org.tests.inherit; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + +@Entity +@DiscriminatorValue("2") +public class DIntChild2 extends DIntChildBase { + + @Override + public String getName() { + return "Name2"; + } + + public DIntChild2(Integer number, String more) { + super(number, more); + } + +} diff --git a/src/test/java/org/tests/inherit/DIntChildBase.java b/src/test/java/org/tests/inherit/DIntChildBase.java new file mode 100644 index 000000000..747a995c9 --- /dev/null +++ b/src/test/java/org/tests/inherit/DIntChildBase.java @@ -0,0 +1,17 @@ +package org.tests.inherit; + +import javax.persistence.Entity; + +@Entity +public class DIntChildBase extends DIntParent { + + @Override + public String getName() { + return "Base name"; + } + + public DIntChildBase(Integer number, String more) { + super(number, more); + } + +} diff --git a/src/test/java/org/tests/inherit/DIntParent.java b/src/test/java/org/tests/inherit/DIntParent.java new file mode 100644 index 000000000..1b491a9bd --- /dev/null +++ b/src/test/java/org/tests/inherit/DIntParent.java @@ -0,0 +1,46 @@ +package org.tests.inherit; + +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; +import javax.persistence.Table; + +@Entity +@Table(name = "dint_parent") +@Inheritance(strategy = InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.INTEGER) +public abstract class DIntParent { + + @Id + private Long id; + + private Integer val; + + private String more; + + protected DIntParent(Integer val, String more) { + this.val = val; + this.more = more; + } + + public abstract String getName(); + + public Long getId() { + return id; + } + + public Integer getVal() { + return val; + } + + public String getMore() { + return more; + } + + public void setMore(String more) { + this.more = more; + } +} diff --git a/src/test/java/org/tests/inherit/InheritDiscIntTest.java b/src/test/java/org/tests/inherit/InheritDiscIntTest.java new file mode 100644 index 000000000..3b892b864 --- /dev/null +++ b/src/test/java/org/tests/inherit/InheritDiscIntTest.java @@ -0,0 +1,22 @@ +package org.tests.inherit; + +import io.ebean.DB; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.Assert.assertNotNull; + +public class InheritDiscIntTest { + + @Test + public void test() { + + DIntChild2 child2 = new DIntChild2(42, "fortyTwo"); + DB.save(child2); + + final DIntParent found = DB.find(DIntParent.class, child2.getId()); + assertNotNull(found); + + assertThat(found).isInstanceOf(DIntChild2.class); + } +}