开发者

HQL CASE statement usage

开发者 https://www.devze.com 2023-04-09 00:23 出处:网络
I\'m using HQL and have this query <query name=\"rule.myRule.query.by.name\"> <![CDATA[ FROM rule.myRule as cr

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号