我正在使用HQL并拥有此查询
<query name="rule.myRule.query.by.name">
<![CDATA[
FROM rule.myRule as cr
WHERE cr.name LIKE :name
AND cr.type = 'myType'
CASE
WHEN COUNT(cr.childRules) > 0
THEN
cr.childRules LIKE :name
]]>
</query>
我需要一些帮助才能使此查询正确无误。我想要的是条件cr.childeRule LIKE:name只在cr.childRules&gt; 0的计数时执行。
我哪里错了?
答案 0 :(得分:1)
FROM rule.myRule as cr
left join cr.childRules childRule
WHERE cr.name LIKE :name
AND cr.type = 'myType'
and childRule.id is null or childRule.name = :name
应该做你想做的事。