【问题标题】:Drools rule with not condition with multiple condition causing error没有条件的 Drools 规则与多个条件导致错误
【发布时间】:2020-06-30 04:19:22
【问题描述】:

当我将以下条件与“不”一起使用时,我得到了一个错误。

    not(Obj1(value == 0) && Obj2(value <= 3))

但是,如果我将上述条件替换如下,我不会收到任何强制转换异常

    Obj1(value != 0) or Obj2(value > 3)

规则如下:

rule "test_6"
salience 10
    when
         not(Obj1(value == 0) && Obj2(value <= 3))
    then
        .....
end

这是我得到的错误:

throwing error Error Message: org.drools.core.rule.GroupElement cannot be cast to org.drools.core.rule.Pattern

【问题讨论】:

    标签: drools rule-engine


    【解决方案1】:

    &amp;&amp;|| 运算符只能在单个模式中使用。例如:Obj1( value &gt; 3 &amp;&amp; value &lt; 10 || value == 0)。根据the documentation,要分离Pattern,必须使用andor 运算符。

    所以,在你的情况下,你的规则应该是:

    rule "test_6"
    salience 10
        when
             not(Obj1(value == 0) and Obj2(value <= 3))
        then
            .....
    end
    

    请注意,当您使用 or 时它并没有失败,因为这是正确的运算符,而不是 ||

    希望对你有帮助,

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-16
      相关资源
      最近更新 更多