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

Sobhana sobhanarich at yahoo.com
Mon Jun 1 12:42:04 EDT 2009


hi, can someone please help with the below issue? Any tips or hints on what
could be causing this would be very helpful.

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,
Sobhana
-- 
View this message in context: http://www.nabble.com/ClassCastException-for-Hibernate-entity-when-rule-is-fired-tp23767583p23767583.html
Sent from the drools - user mailing list archive at Nabble.com.




More information about the rules-users mailing list