mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#2195 - @Aggregation on OneToMany property not mapping to column properly
This commit is contained in:
@@ -16,16 +16,16 @@ public class TEventMany {
|
||||
@ManyToOne
|
||||
TEventOne event;
|
||||
|
||||
int units;
|
||||
int myUnits;
|
||||
|
||||
double amount;
|
||||
|
||||
@Version
|
||||
Long version;
|
||||
|
||||
public TEventMany(String description, int units, double amount) {
|
||||
public TEventMany(String description, int myUnits, double amount) {
|
||||
this.description = description;
|
||||
this.units = units;
|
||||
this.myUnits = myUnits;
|
||||
this.amount = amount;
|
||||
}
|
||||
|
||||
@@ -53,12 +53,12 @@ public class TEventMany {
|
||||
this.event = event;
|
||||
}
|
||||
|
||||
public int getUnits() {
|
||||
return units;
|
||||
public int getMyUnits() {
|
||||
return myUnits;
|
||||
}
|
||||
|
||||
public void setUnits(int units) {
|
||||
this.units = units;
|
||||
public void setMyUnits(int myUnits) {
|
||||
this.myUnits = myUnits;
|
||||
}
|
||||
|
||||
public double getAmount() {
|
||||
|
||||
@@ -37,10 +37,10 @@ public class TEventOne {
|
||||
@Aggregation("count(logs.id)")
|
||||
Long count;
|
||||
|
||||
@Aggregation("sum(logs.units)")
|
||||
@Aggregation("sum(logs.myUnits)")
|
||||
Double totalUnits;
|
||||
|
||||
@Aggregation("sum(logs.units * logs.amount)")
|
||||
@Aggregation("sum(logs.myUnits * logs.amount)")
|
||||
Double totalAmount;
|
||||
|
||||
@OneToMany(mappedBy = "event", cascade = CascadeType.ALL)
|
||||
|
||||
@@ -110,7 +110,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
assertThat(list).isNotEmpty();
|
||||
|
||||
String sql = sqlOf(query2, 5);
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("from tevent_one t0 join tevent_many u1 on u1.event_id = t0.id ");
|
||||
assertThat(sql).contains("where u1.description like ");
|
||||
assertThat(sql).contains(" group by t0.id, t0.name having count(u1.id) >= ? order by t0.name");
|
||||
@@ -132,13 +132,13 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
|
||||
String sql = sqlOf(query, 5);
|
||||
if (isH2()) {
|
||||
assertThat(sql).contains("select distinct t0.id, t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount), sum(u1.units), t0.name from tevent_one t0 ");
|
||||
assertThat(sql).contains("select distinct t0.id, t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount), sum(u1.my_units), t0.name from tevent_one t0 ");
|
||||
} else if (isPostgres()) {
|
||||
assertThat(sql).contains("t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount), sum(u1.units), t0.name from tevent_one t0 ");
|
||||
assertThat(sql).contains("t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount), sum(u1.my_units), t0.name from tevent_one t0 ");
|
||||
}
|
||||
assertThat(sql).contains("from tevent_one t0 join tevent_many u1 on u1.event_id = t0.id ");
|
||||
assertThat(sql).contains(" group by t0.id, t0.name ");
|
||||
assertThat(sql).contains(" order by sum(u1.units), t0.name");
|
||||
assertThat(sql).contains(" order by sum(u1.my_units), t0.name");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -149,7 +149,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
|
||||
query0.findList();
|
||||
String sql = sqlOf(query0, 5);
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.units) from tevent_one t0");
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.my_units) from tevent_one t0");
|
||||
assertThat(sql).contains("group by t0.id, t0.name");
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
|
||||
query0.findList();
|
||||
String sql = sqlOf(query0, 5);
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("group by t0.id, t0.name");
|
||||
}
|
||||
|
||||
@@ -174,7 +174,7 @@ public class TestAggregationCount extends BaseTestCase {
|
||||
|
||||
query0.findList();
|
||||
String sql = sqlOf(query0, 5);
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.units), sum(u1.units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("select t0.id, t0.name, count(u1.id), sum(u1.my_units), sum(u1.my_units * u1.amount) from tevent_one t0");
|
||||
assertThat(sql).contains("group by t0.id, t0.name");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user