【问题标题】:Having trouble with rule that checks two instances of same class检查同一类的两个实例的规则有问题
【发布时间】:2014-10-16 21:05:57
【问题描述】:

我有一条规定

rule "bcs-set"
when
 Param( Feature == "BCS", Name == "primary" )
 Param( Feature == "BCS", Name == "seconday" )
then
 insert ("addition")
end

我创建了两个 Param 对象,但似乎 drools 找不到这两个 Param 对象。

如果我取出第一个参数检查,它可以工作,但不能同时使用规则中的两个参数检查。

Param 类如下:

public class Param {

    private String feature;
    private String name;

    public String getFeature(){
       return feature;
    }

    public void setFeature(String feature){
       this.feature = feature;
    }

    public String getName(){
       return name;
    }

    public void setName(String name){
       this.name = name;
    }

}

有人有什么想法吗?

【问题讨论】:

  • 请提供您用于插入和触发规则的代码。那应该澄清@laune的答案是否正确。

标签: drools drools-guvnor


【解决方案1】:

你很可能做过类似的事情

Param p = new Param();
p.setFeature( "BCS" );
p.setName( "primary" );
kSession.insert( p );
p.setName( "secondary" );
kSession.insert( p );
kSession.fireAllRules();

请注意,插入不会复制;它只是使用参考。 - 应该这样做:

Param p1 = new Param();
p1.setFeature( "BCS" );
p1.setName( "primary" );
kSession.insert( p1 );
Param p2 = new Param();
p2.setFeature( "BCS" );
p2.setName( "secondary" );
kSession.insert( p2 );
kSession.fireAllRules();

当然,您可能还做了其他事情,但这符合您所关联的事实。遗憾的是,您忽略了图片中这个非常重要的部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-04
    • 2018-05-03
    • 1970-01-01
    • 1970-01-01
    • 2019-09-29
    相关资源
    最近更新 更多