Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Hibernate JPA子查询的问题_Hibernate_Jpa_Querydsl - Fatal编程技术网

Hibernate JPA子查询的问题

Hibernate JPA子查询的问题,hibernate,jpa,querydsl,Hibernate,Jpa,Querydsl,我开始使用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.getList

我开始使用
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()
    ));

}
...

我曾经在
QueryDsl 3
中使用
JPASubQuery
,但在版本4中它不再存在了您将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
    ));
其中位置和(prj.id.in(
JPAExpressions.select(loc_2.projet.id).from(loc_2)
.where(loc_2.commune.id.eq(bean.commune))

//.fetch()更新了答案,如果正确的jar.Fully限定路径是
com.querydsl.jpa.JPASubQuery
更新了答案。谢谢@Lesiak it work now…只需删除错误的答案,以免混淆