mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add test for old 408 bug - does not reproduce, not sure when fixed at this point
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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<MProfile> 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
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user