Collections in QueryDSL projections

為{幸葍}努か 提交于 2019-12-04 09:50:13

Using collections in projections is unreliable in JPA. It is safer to join the collection and aggregate the results instead.

Querydsl can also be used for result aggregation http://www.querydsl.com/static/querydsl/3.2.0/reference/html/ch03s02.html#d0e1799

In your case something like this

QRendition rendition = QRendition.rendition;
Projection projection = from(rendition)
    .innerJoin(rendition.document, document) 
    .innerJoin(rendition.resources, resource)  
    .where(document.id.eq(documentId))
    .limit(1)
    .transform(
         groupBy(document.id).as(
            new QProjection(set(resources), 
                document.pageCount,
                document.code)));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!