Skip to content

Commit

Permalink
Added two tests that show issues with grouping joined entities #194
Browse files Browse the repository at this point in the history
  • Loading branch information
jwgmeligmeyling authored and beikov committed Nov 23, 2018
1 parent d9377a5 commit 4cf7f1a
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,72 @@ public void work(EntityManager em) {
});
}

@Test
public void implicitGroupByImplicitlyJoinedEntityTest() {
// Not sure if we want to support implicit group by's here
CriteriaBuilder<Tuple> tupleCriteriaBuilder = cbf.create(em, Tuple.class)
.from(Document.class, "d")
.select("d.owner.id", "ownerId")
.select("d.owner.age", "ownerAge")
.select("d.owner.name", "ownerName")
.select("max(d.id)", "latestDocument")
.orderByAsc("d.owner.name")
.orderByAsc("d.owner.age")
.orderByAsc("d.owner.id");

PaginatedCriteriaBuilder<Tuple> page = tupleCriteriaBuilder
.page(0, 10);

page.getResultList();
}

@Test
public void groupByImplicitlyJoinedEntityTest() {
// Test that shows that its not sufficient to group by / order by all used path expressions
CriteriaBuilder<Tuple> tupleCriteriaBuilder = cbf.create(em, Tuple.class)
.from(Document.class, "d")
.select("d.owner.id", "ownerId")
.select("d.owner.age", "ownerAge")
.select("d.owner.name", "ownerName")
.select("max(d.id)", "latestDocument")
.groupBy("d.owner.name")
.groupBy("d.owner.age")
.groupBy("d.owner.id")
.orderByAsc("d.owner.name")
.orderByAsc("d.owner.age")
.orderByAsc("d.owner.id");

PaginatedCriteriaBuilder<Tuple> page = tupleCriteriaBuilder
.page(0, 10);

page.getResultList();
}


@Test
public void groupByJoinedEntityTest() {
// Test that shows that a work around with a manual inner join default
// still fails, because the required join is omitted in the count query
CriteriaBuilder<Tuple> tupleCriteriaBuilder = cbf.create(em, Tuple.class)
.from(Document.class, "d")
.innerJoinDefault("d.owner", "theOwner")
.select("theOwner.id", "ownerId")
.select("theOwner.age", "ownerAge")
.select("theOwner.name", "ownerName")
.select("max(d.id)", "latestDocument")
.groupBy("theOwner.name")
.groupBy("theOwner.age")
.groupBy("theOwner.id")
.orderByAsc("theOwner.name")
.orderByAsc("theOwner.age")
.orderByAsc("theOwner.id");

PaginatedCriteriaBuilder<Tuple> page = tupleCriteriaBuilder
.page(0, 10);

page.getResultList();
}

@Test
public void simpleTest() {
CriteriaBuilder<DocumentViewModel> crit = cbf.create(em, Document.class, "d")
Expand Down

0 comments on commit 4cf7f1a

Please sign in to comment.