1

给定以下实体类:

@Entity
public class Client {

    @Id private
    Long id;
    @CollectionTable
    @ElementCollection
    private List<String> accounts;

    // getters and setters here     
}

我想查找其任何帐号等于(不区分大小写)搜索词的所有客户。尝试了以下 JPQL,但没有成功:

select c from Client c join c.accounts a where upper(a) = ?1

在 EclipseLink 2.4.2 和 2.5 上,这都失败,并出现以下异常:

Exception Description: Syntax error parsing [select c from Client c join c.accounts a
where upper(a) = ?1]. 
[53, 54] The encapsulated expression is not a valid expression.     

当更改@ElementCollection 以使用具有@OneToMany 的帐号的成熟实体时,一切正常。此外,当从 jpql 中删除 upper() 时,查询运行正常。最终我们将要为此使用 QueryDSL,但目前这个 querydsl 查询

QClient qc = QClient.client;
StringPath a = Expressions.stringPath("a")
new JPAQuery(em).from(qc).innerJoin(qc.accounts, a).where(a.upper().eq(term)).list(qc)

还有这个

new JPAQuery(em).from(qc).where(qc.accounts.any().upper().eq(term)).list(qc)

失败并出现类似错误,大概是因为它们被翻译成相同的 jpql。

如何更改任何这些查询以产生所需的结果?

4

0 回答 0