fetchResults() generating wrong count query #1472

Closed
renanleandrof opened this Issue Aug 11, 2015 · 0 comments

Projects

None yet

2 participants

@renanleandrof

QueryDSL: 4.0.3

Given the scenario:

Document.java

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

@Id
private Long id;

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

@Column
private BigDecimal value;
...
}

SubDepartment.java

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

@Id
private Long id;

@Embedded
private Department department;
...
}

Department.java

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

@Id
private Long id;

@Column(name="departmentCode")
private String code;

@Column(name="departmentName")
private String name;
...
}

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

jpaQueryFactory.from(qDocument)
.select(qDocument.value.sum(), qDocument.subDepartment.department.code)
.groupBy(qDocument.subDepartment.department.code)
.fetchResults();

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