[rules-users] Getting java.lang.ClassCastException: - using Drools 5.3
Wolfgang Laun
wolfgang.laun at gmail.com
Wed Feb 29 02:12:26 EST 2012
This is a bug in the DRL parser/builder. Even when you (as you should)
omit the parentheses around the patterns "Medication" and "Procedure"
(see below) you get the same exception:
( $Dx1 : Medication( name == "Oflo" )
and
eval($x.check($Dx1) )
)
or
( $Dx2 : Procedure( name == "Pre" )
and
eval($x.checks($Dx2) )
)
However, you can use a workaround with the semantically equivalent inline eval:
( $Dx1 : Medication( name == "Oflo", eval($x.check($Dx1) )
or
$Dx2 : Procedure( name == "Pre", eval($x.checks($Dx2) ) )
Note: The similarity between treatment by Medication and Procedure
suggests that there should be an interface Treatment implemented by
both, so you might simplify this to
$Dx1: Treatment( name == "Oflo" || == "Pre", eval( $x.checks( $Dx1 ) )
-W
On 29/02/2012, kashif10 <kash452 at yahoo.com> wrote:
> HI.
> I am getting following exception.
>
> Exception in thread "main" org.drools.RuntimeDroolsException:
> d1.rule.Rule_8f09c0aa350100000080cb1e0dd40f6fEval4Invoker at f6f66af4 :*
> java.lang.ClassCastException: d1.rule.facts.Medication cannot be cast to
> d1.rule.facts.Procedure*
> at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:119)
> at
> org.drools.reteoo.EvalConditionNode.assertLeftTuple(EvalConditionNode.java:178)
> at
> org.drools.reteoo.SingleLeftTupleSinkAdapter.doPropagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:197)
> at
> org.drools.reteoo.SingleLeftTupleSinkAdapter.propagateAssertLeftTuple(SingleLeftTupleSinkAdapter.java:72)
> at org.drools.reteoo.JoinNode.assertObject(JoinNode.java:161)
> at
> org.drools.reteoo.CompositeObjectSinkAdapter.doPropagateAssertObject(CompositeObjectSinkAdapter.java:458)
> at
> org.drools.reteoo.CompositeObjectSinkAdapter.propagateAssertObject(CompositeObjectSinkAdapter.java:386)
> at org.drools.reteoo.AlphaNode.assertObject(AlphaNode.java:134)
> at
> org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:59)
> at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:215)
> at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:244)
> at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:330)
> at org.drools.common.NamedEntryPoint.insert(NamedEntryPoint.java:291)
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:886)
> at
> org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:845)
> at
> org.drools.impl.StatefulKnowledgeSessionImpl.insert(StatefulKnowledgeSessionImpl.java:255)
> at d1.rule.facts.PatientFacts.loadFactsInSession(PatientFacts.java:6075)
> at d1.rule.DREvaluator.startEvaluation(DREvaluator.java:278)
> at d1.rule.DREvaluator.main(DREvaluator.java:72)
> Caused by: java.lang.ClassCastException: d1.rule.facts.Medication cannot be
> cast to d1.rule.facts.Procedure
> at
> d1.rule.Rule_8f09c0aa350100000080cb1e0dd40f6fEval4Invoker.evaluate(Unknown
> Source)
> at org.drools.rule.EvalCondition.isAllowed(EvalCondition.java:114)
>
>
>
> Following is the rule. I found that due to "or" the Procedure block not
> runs.
> If I change "or" to "and" than procedure block executed & the error not
> produced.
> I am not sure what's the problem, I am using Drool 5.3
>
> rule "8f09c0aa350100000080cb1e0dd40f6f"
>
> when #conditions
>
> (
>
> $cepFacts: CEPFacts(id=="D1")
> and
> eval($cepFacts.initialize())
>
> and
>
> (
> (
> $DxDate_1 : ( Medication( name equalsIgnoreCase "Ofloxacin" ) )
> and
> eval($cepFacts.checkRelativeValues($DxDate_1) )
> )
> or
> (
>
> $DxDate_2 : ( Procedure( name equalsIgnoreCase "Pres antibiotic" )
> )
> and
> eval($cepFacts.checkRelativeValues($DxDate_2) )
> )
> )
> and
> (
>
> $DxDate_3 : ( Medication( name equalsIgnoreCase "Trazodone" ) )
> and
> eval($cepFacts.checkTimeIs($DxDate_3)
>
> )
>
> )
> then
>
> resultIds.add("8f09c0aa350100000080cb1e0dd40f6f");
>
> end
>
> --
> View this message in context:
> http://drools.46999.n3.nabble.com/Getting-java-lang-ClassCastException-using-Drools-5-3-tp3785966p3785966.html
> Sent from the Drools: User forum mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
More information about the rules-users
mailing list