我在Spring存储库中有这个JPA查询定义
@Query(value="select rd.contractID as contractID, rd.gicCode as gicCode, count(rd) as ticketNo"
+ " from RawData rd"
+ " where rd.contractID is not null and ((rd.contractCostObject is null and rd.domestic = true) or (rd.mirrorSVO is null and rd.domestic = false))"
+ " group by rd.contractID, rd.gicCode")
但是生成的SQL查询就是那个
select
rawdata0_.contractID as col_0_0_,
rawdata0_.gicCode as col_1_0_,
count(rawdata0_.id) as col_2_0_
from
RawData rawdata0_
where
(
rawdata0_.contractID is not null
)
and (
(
rawdata0_.contractCostObject is null
)
and rawdata0_.domestic=true
or (
rawdata0_.mirrorSVO is null
)
and rawdata0_.domestic=false
)
group by
rawdata0_.contractID ,
rawdata0_.gicCode
您可以看到方括号已更改,并且我相信两个查询中的条件并不相同。 是虫子吗? 在带有postgresql数据库的spring上使用hibernate。
答案 0 :(得分:0)
[core]
repositoryformatversion = 0
filemode = false
bare = false
logallrefupdates = true
symlinks = false
ignorecase = true
[remote "origin"]
url = my ssh url
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
运算符的优先级高于and
运算符。
等同于
将此规则应用于您的查询,实际结果类似于:
or
正是您想要的。 JPA生成的查询是正确的。