fetchResults() generating wrong count query #1472

renanleandrof opened this Issue Aug 11, 2015 · 0 comments


None yet

2 participants


QueryDSL: 4.0.3

Given the scenario:


@Table(name = "document")
public class Document {

private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "subDepartmentId", nullable = false)
private SubDepartment subDepartment;

private BigDecimal value;


@Table(name = "subDepartment")
public class SubDepartment{

private Long id;

private Department department;


@Table(name = "department")
public class Department{

private Long id;

private String code;

private String name;

When i try to do an aggregation query with some group by, it generates a wrong count query in fetchResults:

.select(qDocument.value.sum(), qDocument.subDepartment.department.code)

The generated count is:

SELECT count(s.deparmentCode) AS col_0_0_
FROM document d CROSS JOIN
  subDepartment s
WHERE d.subDepartmentId = s.id

GROUP BY s.departmentCode

That will generate multiple results, not a single result.

Is this a bug or am i doing something wrong?

@timowest timowest added the bug label Aug 12, 2015
@timowest timowest added the progress label Aug 25, 2015
@Shredder121 Shredder121 closed this in #1498 Aug 31, 2015
@timowest timowest added this to the 4.0.4 milestone Aug 31, 2015
@timowest timowest removed the progress label Aug 31, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment