Chris

   Version 3.0.x prevents by default a single fact from matching multiple patterns. For a couple of reasons we had to change the default in 4.0 to allow a single fact to match multiple patterns. If you don't want this to happen, you can use one of the following approaches:

* Change the behavior for the whole rulebase. You can do that by either setting a system property ("drools.removeIdentities=true") or creating a RuleBaseConfiguration instance:

RuleBaseConfiguration conf = new RuleBaseConfiguration();
conf.setRemoveIdentities( true );
RuleBase rulebase = new ReteooRuleBase( conf );

* Alternativelly, you can manually add a constraint to avoid the behavior for specific rules, using the "this" keyword.

rule "TwoCheeses"
    when
        $cheese1 : Cheese();
        $cheese2 : Cheese( this != $cheese1 );       
    then
        System.out.println($cheese1);
        System.out.println($cheese2);
        System.out.println ("TwoCheeses");       
end


    We will add such information to the documentation, but the above shall give you the idea.

    Hope it helps,
      Edson

2007/5/15, Chris Woodrow < woodrow.chris@gmail.com>:
Hi everyone,
I am new to this mailing list, I've had a quick look at archives and didn't find anything ont this subject but sorry if this has allready been underlined.

Here is my problem, while I was doing some test on v3.0.6, 4.0.0 came out, so I started to migrate on the new version. Then I found out an unexpecteed behavior on the 4.0.0.

I have been compiling both with Java 5 and running whith Java 1.5.0_11. And I used versions with dependencies on both tests.

I have made an exemple for you to make it as clear as possible, here is the rule :

---------------------------------------------------------------------------------------
package rules

rule "TwoCheeses"
    when
        $cheese1 : Cheese();
        $cheese2 : Cheese();       
    then
        System.out.println($cheese1);
        System.out.println($cheese2);
        System.out.println("TwoCheeses");       
end
---------------------------------------------------------------------------------------

When I run it on V3.0.6, with this code :

---------------------------------------------------------------------------------------
package rules;

import java.io.InputStreamReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.WorkingMemory;
import org.drools.compiler.PackageBuilder;

public class Cheese {
    public static void main(String[] args) throws Exception{
        PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl(new InputStreamReader(Cheese.class.getResourceAsStream ("rule.drl")));
       
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
       
        ruleBase.addPackage(builder.getPackage());
       
        WorkingMemory workingMemory = ruleBase.newWorkingMemory ();

        Cheese cheese = new Cheese();

        workingMemory.assertObject(cheese);
       
        workingMemory.fireAllRules();
    }
}
---------------------------------------------------------------------------------------

The rule doesn't fire, which is normal AMHA since only one Cheese object is asserted to the WM

When I run it on V4.0.0, whith this code :
---------------------------------------------------------------------------------------
package rules;

import java.io.InputStreamReader;

import org.drools.RuleBase;
import org.drools.RuleBaseFactory;
import org.drools.StatefulSession;
import org.drools.compiler.PackageBuilder;

public class Cheese {
    public static void main(String[] args) throws Exception{
        PackageBuilder builder = new PackageBuilder();
        builder.addPackageFromDrl(new InputStreamReader(Cheese.class.getResourceAsStream ("rule.drl")));
       
        RuleBase ruleBase = RuleBaseFactory.newRuleBase();
       
        ruleBase.addPackage(builder.getPackage());
       
        StatefulSession statefulSession = ruleBase.newStatefulSession();

        Cheese cheese = new Cheese();

        statefulSession.assertObject(cheese);
       
        statefulSession.fireAllRules();
    }
}
---------------------------------------------------------------------------------------
Now the rule fires and $cheese1 $cheese2 have the same reference.

I have been searching in all docs, this modification of behavior doesn't seem to be expected, has anyone noticed this?

Thanks for your help.

Chris



_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com