【发布时间】:2014-11-06 13:05:24
【问题描述】:
环境:
- hibernate-entitymanager:4.3.6.Final
- PostgreSQL 9.3.5
我执行当前这个 JPQL 查询
select distinct entity
from Incidence entity
left join treat(entity.road as Road) as road
where entity.road is not null and lower(road.nomenclature) like :value
查看日志文件,这会为 PostgreSQL 生成以下查询:
select
distinct
....
....
from public.incidence incidence0_
left outer join public.road road1_
on incidence0_.road=road1_.id and null=null
where (incidence0_.road is not null) and (lower(road1_.nomenclature) like ? )
使用%cv% 作为参数,这个查询应该返回 175 行,但我没有得到。
如果我在 PostgreSQL 上运行评论 and null=null 的查询,我会得到预期的结果:
select
distinct
....
....
from public.incidence incidence0_
left outer join public.road road1_
on incidence0_.road=road1_.id /* and null=null */
where (incidence0_.road is not null) and (lower(road1_.nomenclature) like '%cv%' )
那么...为什么 hibernate 会在左连接中添加“null=null”条件?
我已经用 Oracle 进行了尝试,得到了完全相同的结果。
【问题讨论】:
标签: hibernate postgresql jpa jpql