diff --git a/src/test/java/com/avaje/tests/model/inheritmany/MBase.java b/src/test/java/com/avaje/tests/model/inheritmany/MBase.java new file mode 100644 index 000000000..5e21d5c5e --- /dev/null +++ b/src/test/java/com/avaje/tests/model/inheritmany/MBase.java @@ -0,0 +1,20 @@ +package com.avaje.tests.model.inheritmany; + +import javax.persistence.Id; +import javax.persistence.MappedSuperclass; + +@MappedSuperclass +public class MBase { + + @Id + Long id; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + +} diff --git a/src/test/java/com/avaje/tests/model/inheritmany/MMedia.java b/src/test/java/com/avaje/tests/model/inheritmany/MMedia.java new file mode 100644 index 000000000..3db7d7403 --- /dev/null +++ b/src/test/java/com/avaje/tests/model/inheritmany/MMedia.java @@ -0,0 +1,25 @@ +package com.avaje.tests.model.inheritmany; + +import javax.persistence.DiscriminatorColumn; +import javax.persistence.DiscriminatorType; +import javax.persistence.Entity; +import javax.persistence.Inheritance; +import javax.persistence.InheritanceType; + +@Entity +@Inheritance(strategy=InheritanceType.SINGLE_TABLE) +@DiscriminatorColumn(discriminatorType=DiscriminatorType.STRING, name = "type") +public class MMedia extends MBase { + + String url; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + +} \ No newline at end of file diff --git a/src/test/java/com/avaje/tests/model/inheritmany/MPicture.java b/src/test/java/com/avaje/tests/model/inheritmany/MPicture.java new file mode 100644 index 000000000..9c505cace --- /dev/null +++ b/src/test/java/com/avaje/tests/model/inheritmany/MPicture.java @@ -0,0 +1,22 @@ +package com.avaje.tests.model.inheritmany; + +import javax.persistence.DiscriminatorValue; +import javax.persistence.Entity; + + +@Entity +@DiscriminatorValue("Picture") +public class MPicture extends MMedia { + + + String note; + + public String getNote() { + return note; + } + + public void setNote(String note) { + this.note = note; + } + +} diff --git a/src/test/java/com/avaje/tests/model/inheritmany/MProfile.java b/src/test/java/com/avaje/tests/model/inheritmany/MProfile.java new file mode 100644 index 000000000..dbadc848b --- /dev/null +++ b/src/test/java/com/avaje/tests/model/inheritmany/MProfile.java @@ -0,0 +1,31 @@ +package com.avaje.tests.model.inheritmany; + +import javax.persistence.CascadeType; +import javax.persistence.Entity; +import javax.persistence.ManyToOne; + +@Entity +public class MProfile extends MBase { + + @ManyToOne(cascade = CascadeType.ALL) + MPicture picture; + + String name; + + public MPicture getPicture() { + return picture; + } + + public void setPicture(MPicture picture) { + this.picture = picture; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +} diff --git a/src/test/java/com/avaje/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java b/src/test/java/com/avaje/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java new file mode 100644 index 000000000..bc5759362 --- /dev/null +++ b/src/test/java/com/avaje/tests/model/inheritmany/TestMediaInheritanceJoinToMany.java @@ -0,0 +1,38 @@ +package com.avaje.tests.model.inheritmany; + +import org.junit.Assert; +import org.junit.Test; + +import com.avaje.ebean.BaseTestCase; +import com.avaje.ebean.Ebean; +import com.avaje.ebean.Query; + +public class TestMediaInheritanceJoinToMany extends BaseTestCase { + + @Test + public void test() { + + + String name = "nopic"; + + MProfile profileWithNoPic = new MProfile(); + profileWithNoPic.setName(name); + + Ebean.save(profileWithNoPic); + + Query query = Ebean.find(MProfile.class).fetch("picture").where().eq("name", name).query(); + + // assert we get the profile with a null picture + MProfile profile = query.findUnique(); + Assert.assertNotNull(profile); + + // select t0.id c0, t0.name c1, t1.type c2, t1.id c3, t1.url c4, t1.note c5 + // from profile t0 + // left outer join media t1 on t1.id = t0.picture_id and t1.type = 'Picture' + // where t0.name = ? ; --bind(nopic) + + // specifically t1.type = 'Picture' ... on on the join and not in the where + + } + +}