user3934365
user3934365

Reputation: 7

Having trouble with rule that checks two instances of same class

I have a rule that says

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

I have created two Param objects but it seems like drools can't find both of the Param objects.

If I take out the first Param check it works but not with both of the Param checks in the rule.

The Param class is as follows:

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;
    }

}

Anyone has any ideas?

Upvotes: 0

Views: 115

Answers (1)

laune
laune

Reputation: 31290

It's very likely that you have done something like

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

Note that insert doesn't copy; it just uses the reference. - This is how it should be done:

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();

It is, of course, possible that you have done something else, but this fits the facts as you have related them. Sadly, you have omitted this highly important part of the picture.

Upvotes: 1

Related Questions