JPA子查询问题

问题描述 投票:0回答:1

我开始使用QueryDsl 4我得到了这个错误

java.lang.UnsupportedOperationException
    at com.querydsl.jpa.JPASubQuery.iterate(JPASubQuery.java:72)
    at com.querydsl.core.support.FetchableQueryBase.fetch(FetchableQueryBase.java:46)
    at dao.SearchProjetDao.getListProjetsQueryDsl(SearchProjetDao.java:108)
    at controllers.ProjetRest.getListProjetsQueryDsl(ProjetRest.java:82)

当我尝试这个子查询

QProjet prj = new QProjet("prj");
...
BooleanBuilder where_loc = new BooleanBuilder();

if( bean.commune != null ){

    QLocalisation loc_2 = new QLocalisation("loc_2");

    where_loc.and(prj.id.in( 
            JPAExpressions.select(loc_2.projet.id).from(loc_2)
            .where(loc_2.commune.id.eq(bean.commune))
            .fetch()
    ));

}
...

我以前在JPASubQuery中使用QueryDsl 3但它在版本4中不再存在

hibernate jpa querydsl
1个回答
1
投票

你把fetch放在了错误的地方。

where_loc.and(prj.id.in( 
            JPAExpressions.select(loc_2.projet.id).from(loc_2)
            .where(loc_2.commune.id.eq(bean.commune))
         //   .fetch()  <--- Remove
    ));

期望(或其他)

  • SubQueryExpression - 修改后的代码选择的重载
  • Collection - 错误代码选择的重载。 (我认为这些应该是常量)

Subquery Examples in QueryDls4 doc

© www.soinside.com 2019 - 2024. All rights reserved.