HQL CASE statement usage
I'm using HQL and have this query
<query name="rule.myRule.query.by.name">
<![CDATA[
FROM rule.myRule as cr
WHERE cr.name LIKE :name
AND cr.type = 'myType'
开发者_Go百科 CASE
WHEN COUNT(cr.childRules) > 0
THEN
cr.childRules LIKE :name
]]>
</query>
I need some help making this query correct. What I want is to have the condition cr.childeRule LIKE :name execute only when the count of cr.childRules >0 .
Where am I wrong ?
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
should do what you want.
精彩评论