我正在考虑使用 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,而且看起来每个 MyDtoObjects 只保存一个entityTwo 对象而不是一个集合。
如何指示 queryDSL 创建具有多个entityTwo 条目的 MyDtoObjects 结果对象? list(..) 方法在我上面的场景中是否执行任何操作?
queryFactory.from(Entity)
.transform(groupBy(Entity.something).list((
Projections.fields(EntityDto.class,
list(Projections.fields(Dto.class,
)).as("CollectionEntity"),
)));
尝试用列表进行转换
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)