<br> Chris<br><br> 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:
<br><br>* 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:<br><br>RuleBaseConfiguration conf = new RuleBaseConfiguration();
<br>conf.setRemoveIdentities( true );<br>RuleBase rulebase = new ReteooRuleBase( conf );<br><br>* Alternativelly, you can manually add a constraint to avoid the behavior for specific rules, using the "this" keyword.
<br><br>rule "TwoCheeses"
<br> when<br> $cheese1 : Cheese();<br> $cheese2 : Cheese( this != $cheese1 ); <br> then <br> System.out.println($cheese1);<br> System.out.println($cheese2);<br> System.out.println
("TwoCheeses");
<br>end<br><br><br> We will add such information to the documentation, but the above shall give you the idea.<br><br> Hope it helps,<br> Edson<br><br><div><span class="gmail_quote">2007/5/15, Chris Woodrow <
<a href="mailto:woodrow.chris@gmail.com">woodrow.chris@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi everyone,
<br>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.<br><br>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.<br><br>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.
<br><br>I have made an exemple for you to make it as clear as possible, here is the rule :<br><br>---------------------------------------------------------------------------------------<br>package rules<br><br>rule "TwoCheeses"
<br> when<br> $cheese1 : Cheese();<br> $cheese2 : Cheese(); <br> then <br> System.out.println($cheese1);<br> System.out.println($cheese2);<br> System.out.println("TwoCheeses");
<br>end<br>---------------------------------------------------------------------------------------<br><br>When I run it on V3.0.6, with this code :<br><br>---------------------------------------------------------------------------------------
<br>package rules;<br><br>import java.io.InputStreamReader;<br><br>import org.drools.RuleBase;<br>import org.drools.RuleBaseFactory;<br>import org.drools.WorkingMemory;<br>import org.drools.compiler.PackageBuilder;<br><br>
public class Cheese {<br> public static void main(String[] args) throws Exception{<br> PackageBuilder builder = new PackageBuilder();<br> builder.addPackageFromDrl(new InputStreamReader(Cheese.class.getResourceAsStream
("rule.drl")));<br> <br> RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br> <br> ruleBase.addPackage(builder.getPackage());<br> <br> WorkingMemory workingMemory = ruleBase.newWorkingMemory
();<br><br> Cheese cheese = new Cheese();<br><br> workingMemory.assertObject(cheese);<br> <br> workingMemory.fireAllRules();<br> }<br>}<br>---------------------------------------------------------------------------------------
<br><br>The rule doesn't fire, which is normal AMHA since only one Cheese object is asserted to the WM<br><br>When I run it on V4.0.0, whith this code :<br>---------------------------------------------------------------------------------------
<br>package rules;<br><br>import java.io.InputStreamReader;<br><br>import org.drools.RuleBase;<br>import org.drools.RuleBaseFactory;<br>import org.drools.StatefulSession;<br>import org.drools.compiler.PackageBuilder;<br>
<br>
public class Cheese {<br> public static void main(String[] args) throws Exception{<br> PackageBuilder builder = new PackageBuilder();<br> builder.addPackageFromDrl(new InputStreamReader(Cheese.class.getResourceAsStream
("rule.drl")));<br> <br> RuleBase ruleBase = RuleBaseFactory.newRuleBase();<br> <br> ruleBase.addPackage(builder.getPackage());<br> <br> StatefulSession statefulSession =
ruleBase.newStatefulSession(); <br><br> Cheese cheese = new Cheese();<br><br> statefulSession.assertObject(cheese);<br> <br> statefulSession.fireAllRules();<br> }<br>}<br>---------------------------------------------------------------------------------------
<br>Now the rule fires and $cheese1 $cheese2 have the same reference.<br><br>I have been searching in all docs, this modification of behavior doesn't seem to be expected, has anyone noticed this?<br><br>Thanks for your help.
<br><span class="sg"><br>Chris<br><br><br>
</span><br>_______________________________________________<br>rules-users mailing list<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<br><a onclick="return top.js.OpenExtLink(window,event,this)" href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br><br></blockquote></div>
<br><br clear="all"><br>-- <br> Edson Tirelli<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">
www.jboss.com</a>