0

基于以下文章 JPQL,或者只返回一个条件的结果? 我创建了以下查询

Collection<Profile> profiles = dataManager.load(Profile.class).view("profile-view")
        .query("select p from userlifecyclemgmt_Profile p " +
                " left join p.legalEntities f where" + 
                " p.isAvailableForAll = true or :legalEntity MEMBER OF f" ) 
        .parameter("legalEntity", serviceRequest.getHrUser().getLegalEntity())
        .list();

参数:legalEntity是类的对象LegalEntity。此查询给了我以下错误:

JpqlSyntaxException: Errors found for input jpql:[select p from userlifecyclemgmt_Profile p  left join p.legalEntities f where p.isAvailableForAll = true or :legalEntity MEMBER OF f]
CommonErrorNode [<unexpected: [@35,120:125='MEMBER',<113>,1:120], resync=:legalEntity MEMBER OF f>]

使用相同的查询稍作修改:

Collection<Profile> profiles = dataManager.load(Profile.class).view("profile-view")
        .query("select p from userlifecyclemgmt_Profile p " +
                " left join p.legalEntities f where" +
                " p.isAvailableForAll = true or :legalEntity MEMBER OF p.legalEntities" )
        .parameter("legalEntity", serviceRequest.getHrUser().getLegalEntity())
        .list();

没有错误,但只给了我OR语句第二部分的结果。我确实了解 JPQL 在后台创建INNER JOIN查询,这就是原因。但是,如何使第一个查询起作用?

提前致谢!

4

1 回答 1

2

您应该以这种方式修改查询

select distinct p 
from userlifecyclemgmt_Profile p left join p.legalEntities f 
where p.isAvailableForAll=true or f=:legalEntity

from userlifecyclemgmt_Profile p left join p.legalEntities f表达式生成left join返回纯结果的本机查询profile-legalEntityf成为 single 的别名legalEntity,不能用于 in member of,否则p.legalEntities可以。

select plegalEntities.size()多次 ( ) 次返回相同的配置文件。所以你需要distinct.

于 2020-09-02T12:39:36.980 回答