我正在尝试查询搜索结构如下的项目:
IssueCategory
- * Issue
(一对多)
使用以下JPQL
select count(z) from IssueCategory z join z.issues x
where
lower(cast(function('lo_get', cast(x.diagnosis as integer)) as text)) like lower(concat('TEXT TO SEARCH', '%'))
其中诊断是带有Issue
注释的@Lob
字符串字段,映射为postgres中的文本字段:
CREATE TABLE issues (
...
diagnosis text,
...
)
此查询生成以下查询
select count(issuecateg0_.id) as col_0_0_
from issue_categories issuecateg0_
inner join issues issues1_ on issuecateg0_.id=issues1_.category_id
where lower(cast(lo_get(cast(issues1_.diagnosis as int4)) as text)) like lower(('TEXT TO SEARCH'||'%'))
显然,在起源中,“TEXT TO SEARCH”作为参数传递给查询。
问题是:当我执行JPQL查询时,它返回0,但如果我直接在postgres中执行生成的查询,我得到1。
有没有人知道像这样的行为?
答案 0 :(得分:0)
我终于改为以下条件:
lower(function('encode', (function('lo_get', cast(x.diagnosis as integer))), 'escape') like lower(concat('TEXT TO SEARCH', '%'))