【发布时间】:2019-03-07 10:45:40
【问题描述】:
我正在考虑使用 DTO 投影 - 我有两个具有一对多关系的实体(EntityOne 的一个实例链接到 EntityTwo 的多个实例),我想将结果作为新的 DTO 对象返回 -我目前正在尝试的是:
query.select(Projections.constructor(MyDtoObject.class,
entityOne, list(entityTwo)))
.from(entityOne, entityTwo)
.where(......)
MyDtoObject 如下所示:
public class MyDtoObject {
private EntityOne entityOne;
private Collection<EntityTwo> entityTwoCollection
// getters, setters and an all args constructor method here
}
但是,这带来的 MyDtoObjects 比预期的要多得多,而且看起来每个人只持有一个 entityTwo 对象而不是一个集合。
如何指示 queryDSL 创建具有多个 entityTwo 条目的 MyDtoObjects 结果对象? list(..) 方法在我上面的场景中是否有任何作用?
【问题讨论】:
-
我找到了一个相关的答案,它解决了我的问题:stackoverflow.com/questions/17116711/…