mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
BUG: @OrderBy on chained properties do not work with distinct (testcase)
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.OrderBy;
|
||||
import javax.persistence.Table;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "e_basic_tree")
|
||||
public class EBasicTree {
|
||||
|
||||
@Id
|
||||
private int id;
|
||||
|
||||
@ManyToOne
|
||||
private EBasicTree parent;
|
||||
|
||||
@OneToMany
|
||||
@OrderBy("ref.name")
|
||||
private List<EBasicTree> children;
|
||||
|
||||
@ManyToOne
|
||||
private EBasic ref;
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public EBasicTree getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
public void setParent(EBasicTree parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public List<EBasicTree> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
public void setChildren(List<EBasicTree> children) {
|
||||
this.children = children;
|
||||
}
|
||||
|
||||
public EBasic getRef() {
|
||||
return ref;
|
||||
}
|
||||
|
||||
public void setRef(EBasic ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,21 @@ public class TestOrderByWithDistinct extends BaseTestCase {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOrderByOnPropWithDistinct() {
|
||||
Query<EBasicTree> query = DB.find(EBasicTree.class)
|
||||
.fetch("children")
|
||||
.where().eq("children.ref.status", EBasic.Status.ACTIVE).query();
|
||||
|
||||
query.findList();
|
||||
// we expect t2.name in this query
|
||||
assertSql(query).startsWith("select distinct t0.id, t0.parent_id, t0.ref_id, t1.id, t1.parent_id, t1.ref_id, t2.name "
|
||||
+ "from e_basic_tree t0 "
|
||||
+ "left join e_basic_tree t1 on t1.parent_id = t0.id "
|
||||
+ "join e_basic_tree u1 on u1.parent_id = t0.id "
|
||||
+ "join e_basic u2 on u2.id = u1.ref_id left "
|
||||
+ "join e_basic t2 on t2.id = t1.ref_id where u2.status = ? order by t0.id, t2.name");
|
||||
}
|
||||
@Test
|
||||
public void testOrderByWithDistinct() {
|
||||
Query<MUser> query = DB.find(MUser.class);
|
||||
|
||||
Reference in New Issue
Block a user