[rules-users] ClassCastException for Hibernate entity when rule is fired

Sobhana Richard sobhanarich at yahoo.com
Thu May 28 14:45:41 EDT 2009





hi, we are using Drools 4.0.7
and have a rule which uses a Hibernate entity (SaleEventItem) and its related
entity (Inventory). Some times, the SaleEventItem passed as the fact has the
Inventory lazy loaded and hence its type is the Hibernate proxy -
Inventory_$$_javassist_93. In this case, the rule runs fine. 

But at times, the SaleEventItem which is passed has the Inventory attribute set
explicitly and hence its type is Inventory itself. When the rule fires in this
case, it tries to assign the Inventory into Inventory_$$_javassist_93 which
causes this ClassCastException. java.lang.ClassCastException: com.crom.data.pojo.Inventory incompatible with
com.crom.data.pojo.Inventory_$$_javassist_93 

        at
ASMAccessorImpl_14985690421242774005070.getValue(Unknown Source) 

        at
org.mvel.ast.VariableDeepPropertyNode.getReducedValueAccelerated(VariableDeepPropertyNode.java:22)


        at
org.mvel.ast.PropertyASTNode.getReducedValueAccelerated(PropertyASTNode.java:21)


        at org.mvel.ast.BinaryOperation.getReducedValueAccelerated(BinaryOperation.java:21)


        at
org.mvel.MVELRuntime.execute(MVELRuntime.java:90) 

        at
org.mvel.CompiledExpression.getValue(CompiledExpression.java:111) 

        at org.mvel.MVEL.executeExpression(MVEL.java:235) 

        at org.drools.base.mvel.MVELPredicateExpression.evaluate(MVELPredicateExpression.java:45)


        at
org.drools.rule.PredicateConstraint.isAllowed(PredicateConstraint.java:209) 



How do we prevent this? Is it possible to somehow enforce that the type of the variable
in the rule should be Inventory and not Inventory_$$_javassist_93? 



The rule is as follows. 



dialect "java" 

        when 

               
$sale:SaleEventItem(inventory != null, 

                     
      $leaseInfo:inventory.leaseInformation != null, 

                     
     
$saleEventPrize:inventory.leaseInformation.residualPayAmount != null) 

        then 

               
$sale.setStartPrice((Double)$sale.getInventory().getLeaseInformation().getResidualPayAmount());
Thanks,Sobha





      Bollywood news, movie reviews, film trailers and more! Go to http://in.movies.yahoo.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090529/37aef70c/attachment.html 


More information about the rules-users mailing list