@Data
@AllArgumentsConstructor
EntityADTO{
Long id;
String name;
Set<EntityB>;
}
@Data
@AllArgumentsConstructor
EntityBDTO{
Long id;
String name;
}
All class are annotated with Lombok annotations.
What is the correct dsl query, to retrieve only one dto EntityADTO with all populated set of EntityBDTO?
I try the next query, but the results is List of Tuple of projections based by column extracted in defaultEntityAExpression() method and the Set<EntityB> is populated with only one entityB.
sqlQueryFactory.select(defaultEntityAExpression())
.from(entityA)
.join(entityB).on(entityB.fk.eq(entityA.id))
public static Expression<EntityADTO> defaultEntityAExpression() {
//@formatter:off
return Projections.constructor(EntityADTO.class,
entityA.id,
entityA.name,
Projections.list(defaultEntityBexpression()));
//@formatter:on
}
public static Expression<EntityBDTO> defaultEntityBexpression() {
//@formatter:off
return Projections.constructor(EntityBDTO.class,
entityB.id,
entityB.name);
//@formatter:on
}
Map<EntityADTO, List<EntityBDTO>> result = sqlQueryFactory.select(defaultEntityAExpression())
.from(entityA)
.join(entityB).on(entityB.fk.eq(entityA.id))
.transform(GroupBy.groupBy(entityA)).as(list(entityB));