[jboss-jira] [JBoss JIRA] (DROOLS-897) Binding variable or condition
Mario Fusco (JIRA)
issues at jboss.org
Fri Aug 28 04:44:05 EDT 2015
[ https://issues.jboss.org/browse/DROOLS-897?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13103016#comment-13103016 ]
Mario Fusco commented on DROOLS-897:
------------------------------------
In this case the fix that I'm trying to develop won't fix your problem. The thing is that the consequence of a rule is in the end a syntetic Java method having as arguments all the declaration used by the consequence itself. Not having a common class of which type should be your $entity variable in the signature of the Java method implementing the consequence? Or, to rephrase the problem, how would you write a Java method that could call 'setCodDiviCont' on any of the objects of your domain not using reflection as you have been obliged to do to workaround the problem?
My suggestion is to refactor the classes in your domain model putting the common methods and data in a parent class. Does this make sense? In case this is not possible for you (you are not allowed to change the domain model) the only other suggestion I can give you is using a different rule for each of the classes in your domain.
As a side note (not related with this issue) I'm just noticing that you're calling modify twice for the same object in your consequence. This is a performance antipattern since your propagating the modification of that fact twice inside the rete network. Despite this problem is mitigated by the new phreak algorithm implemented in Drools 6.x I suggest you to put both sets in the same modify block as it follows
{code}
modify( $entity ) {
setCodDiviCont($t.get("cod_divi_contab").toString()),
setCambioDiviCont($cambio)
}
{code}
> Binding variable or condition
> -----------------------------
>
> Key: DROOLS-897
> URL: https://issues.jboss.org/browse/DROOLS-897
> Project: Drools
> Issue Type: Bug
> Components: core engine
> Affects Versions: 6.2.0.Final
> Environment: Windows 8
> Reporter: Sante Stanisci
> Assignee: Mario Fusco
> Labels: dynamic, instanciation, variable
> Attachments: rule.drl, workaround.drl
>
>
> In this example I have more classes that extends EntityBase (my class). In my intention, i would assign to variable $entity one of this class that is inserted in Ksession fact.
> I insert fact of CtbMovrCoan class
> In when statement of the rule at row 16, variable $entity is correctely,
> but in then statement variable $entity becomes JtbRLavt class (first declared in then cond) and this behavior throw a ClassCastException, obviously.
> Can Help me?
--
This message was sent by Atlassian JIRA
(v6.3.15#6346)
More information about the jboss-jira
mailing list