#1740 and #1744 Don't include the discriminator column on Inheritance query on a type that has no sub-types

Fix for #1740
This commit is contained in:
rob bygrave
2019-06-30 21:52:01 +12:00
parent eba521563a
commit 8ffc9ede85
9 changed files with 140 additions and 14 deletions
@@ -0,0 +1,18 @@
package org.tests.aggregateformula;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.Table;
@Entity
@Inheritance
@Table(name = "iaf_segment")
@DiscriminatorColumn(name = "ptype")
public class IAFBaseSegment {
@Id
private Long id;
}
@@ -0,0 +1,30 @@
package org.tests.aggregateformula;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.Inheritance;
import javax.persistence.ManyToOne;
@Entity
@Inheritance
@DiscriminatorValue("target")
public class IAFPartialSegment extends IAFBaseSegment {
private final long segmentIdZat;
@ManyToOne(optional = false)
private final IAFSegmentStatus status;
public IAFPartialSegment(long segmentIdZat, IAFSegmentStatus status) {
this.segmentIdZat = segmentIdZat;
this.status = status;
}
public long getSegmentIdZat() {
return segmentIdZat;
}
public IAFSegmentStatus getStatus() {
return status;
}
}
@@ -0,0 +1,35 @@
package org.tests.aggregateformula;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "iaf_segment_status")
public class IAFSegmentStatus {
@Id
private long id;
private String name;
public IAFSegmentStatus(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
@@ -0,0 +1,39 @@
package org.tests.aggregateformula;
import io.ebean.DB;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestAggregateInheritFormula {
@Test
public void test() {
IAFSegmentStatus st0 = new IAFSegmentStatus("st0");
IAFSegmentStatus st1 = new IAFSegmentStatus("st1");
IAFPartialSegment p0 = new IAFPartialSegment(108, st0);
IAFPartialSegment p1 = new IAFPartialSegment(108, st1);
IAFPartialSegment p2 = new IAFPartialSegment(109, st0);
DB.saveAll(Arrays.asList(st0, st1, p0, p1));
LoggedSqlCollector.start();
List<IAFPartialSegment> segments =
DB.find(IAFPartialSegment.class)
.select("segmentIdZat, min(status)")
.where().eq("segmentIdZat", 108L)
.findList();
final List<String> sql = LoggedSqlCollector.stop();
assertThat(segments).hasSize(1);
assertThat(sql.get(0)).contains("select t0.segment_id_zat, min(t0.status_id) from iaf_segment t0 where t0.ptype = 'target' and t0.segment_id_zat = ? group by t0.segment_id_zat");
}
}
@@ -23,7 +23,6 @@ import static org.assertj.core.api.Assertions.assertThat;
public class TestQuerySingleAttribute extends BaseTestCase {
@Test
public void exampleUsage() {
@@ -236,8 +235,7 @@ public class TestQuerySingleAttribute extends BaseTestCase {
.select("more");
query.findSingleAttributeList();
assertThat(sqlOf(query)).contains("select distinct t0.more from rawinherit_parent t0 where t0.type = 'A' ");
assertThat(sqlOf(query)).contains("select distinct t0.more from rawinherit_parent t0 where t0.type = 'A'");
}
@Test