[英]QueryDSL - DTO projections for one-to-many relationship
我正在考虑使用 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(..) 方法甚至在我上面的场景中做任何事情吗?
queryFactory.from(Entity)
.transform(groupBy(Entity.something).list((
Projections.fields(EntityDto.class,
list(Projections.fields(Dto.class,
)).as("CollectionEntity"),
)));
尝试使用列表进行转换
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.