假设我有这两个bean实体:
public class Audit {
private String code;
private java.sql.Timestamp creationDate;
private String creatorId;
private java.sql.Timestamp deletionDate;
private String description;
private String id;
private String name;
private String notes;
private Short status;
private List<AuditParticipant> participants;
}
和:
public class AuditParticipant {
private String auditId;
private String department;
private String id;
private String name;
private String notes;
private String role;
private String surname;
}
... Audit
可以有1..n Participants
,我如何使用QueryDSL SQL将参与者列表投影到Audit bean中(获取属于审计的所有参与者)?
使用QueryDSL代码生成生成bean。
由于
答案 0 :(得分:5)
Querydsl为此类案例http://www.querydsl.com/static/querydsl/3.1.1/reference/html/ch03s02.html#d0e1634
提供结果汇总功能在这种情况下,它会像
query.from(audit)
.innerJoin(participant).on(...)
.transform(groupBy(audit.id).as(audit, list(participant)));
的信息,请参阅这些示例