在JPQL中使用UPPER和ElementCollection

时间:2013-08-05 22:16:42

标签: eclipselink jpql querydsl

给出以下实体类:

@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。

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

0 个答案:

没有答案
相关问题