New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fetchResults() generating wrong count query #1472

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

Comments

Projects
None yet
2 participants
@renanleandrof

renanleandrof commented Aug 11, 2015

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment