[rules-users] Same rules applies twice

Wolfgang Laun wolfgang.laun at gmail.com
Mon Nov 8 04:57:35 EST 2010


Inserting two equal objects results in two facts, and each will trigger a
matching rule.

If your class Result contains a proper implementation of equals() and
hashCode(), you
may use
   KnowledgeBaseConfiguration conf = ....
   conf.setOption( AssertBehaviorOption.IDENTITY );
   KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase( conf );
and then inserting another equal object will be ignored by the engine.

You should not use
  not( exists(...) )
not() alone is the negated existence quantifier. Although not wrong,
it's generally considered to be inelegant and confusing.

-W

2010/11/8 J-C Walmetz <jc7442 at yahoo.fr>

> Hi
>
> I use Drools 5.01
>
> I have the following rules:
>
> rule "Reload test" salience 10000
>     when
>         $result: Result( $resultId:resultId)
>         not (exists Test(resultId.technicalId==$resultId.technicalId))
>     then
>         Test test = createTest($resultId);
>          insert(test);
> end
>
> When I  insert two results with the same identifier, rules is applyed 2
> times. One for each result. I do not understand why.
>
> Do you have an idea of what's happen and how to guratantee that myl rules
> will not be applied twice. Here order is not important ...
>
> Thanks
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101108/fc4bcbdc/attachment.html 


More information about the rules-users mailing list