简体   繁体   English

Drools规则有什么问题?

[英]What is wrong with Drools rule?

I have a long time experience working with JBOSS Drools. 我在JBOSS Drools工作有很长的经验。 current project I'm working with uses Drools 4. 我正在使用的当前项目使用Drools 4。

here is the one of the rules I have in project 这是我在项目中的规则之一

rule "testcase"
   salience 300
    when
        $item : Item(itemTypeId in (Item.ITEM_TYPE_A, Item.ITEM_TYPE_B), targetId < 0)
        not Tegret(targetId == $item.targetId)
    then
        retract ($item);
end

idea is to retract such Items from working memory that does not have associated Target object. 想法是从没有关联目标对象的工作内存中撤回此类项目。 I'm testing it with these objects in working memory: 我正在使用工作内存中的以下对象对其进行测试:

Item {itemId=7305, itemTYpeId=ITEM_TYPE_A, targetId=-1023} Target {targetId = -1023} 项目{itemId = 7305,itemTYpeId = ITEM_TYPE_A,targetId = -1023}目标{targetId = -1023}

in this case rule should not fire, but it does. 在这种情况下,规则不应触发,但是会触发。 after lot of experimenting I have found this strange behaviour: 经过大量的实验,我发现了这种奇怪的行为:

rule "testcase2" fires, while "testcase1" does not. 规则“ testcase2”触发,而“ testcase1”则不触发。

rule "testcase1"
   salience 300
    when        
        $item : Item(itemTypeId in (Item.ITEM_TYPE_A, Item.ITEM_TYPE_B), targetId < 0)
        Tegret(targetId == $item.targetId)
    then
        ...
end

rule "testcase2"
   salience 300
    when        
        $item : Item(itemTypeId in (Item.ITEM_TYPE_A, Item.ITEM_TYPE_B), targetId < 0)
        Tegret($ti:targetId)
        eval($ti == $item.targetId)

    then
        ...
end

so what is going wrong here? 那么这里出了什么问题? I'm running "testcase1" and "testcase2" separately on different program runs. 我在不同的程序运行中分别运行“ testcase1”和“ testcase2”。

Well, after lots of experimenting and fiddling here is what I found: I don't know if is it bug or not, but this was happening due to type differences between "linking" fields. 好吧,经过大量的尝试和摸索,我发现了这里:我不知道它是否有错误,但这是由于“链接”字段之间的类型差异而发生的。

Tagret.targetId is int primitive. Tagret.targetId是int原语。 Item.targetId is long primitive. Item.targetId是长基元。

rewriting rule this way solved the problem: 这样重写规则可以解决问题:

rule "testcase"
   salience 300
    when
        $item : Item(itemTypeId in (Item.ITEM_TYPE_A, Item.ITEM_TYPE_B), targetId < 0)
        not Tegret(targetId == ((long)$item.targetId))
    then
        retract ($item);
end

re-read documentation to find any hints about field "compatibility" restriction. 重新阅读文档以找到有关字段“兼容性”限制的任何提示。 no result 没有结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM