mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user