I am using hibernate with drools ...
rule "login_validation"
when
userRole:UserRole() from hibernateSession.createQuery("select userRoles
from UserAccount ua where ua.name = :name AND ua.password =
:password").setProperties( {"name" : "Hafeez" ,
"password" : "asdasd"
}).list()
then
System.out.println( "--------------------The role " +
userRole.getRoleName()+" is owned by "+userRole.getAccounts());
end
this rule is fired and gives me correct userRole.getRoleName()+" is owned by
"+userRole.getAccounts()
Now i want to give dynamic input to LHS.... i.e. I want to replace "Hafeez"
and "asdasd" with some function ...
for the purpose i create a class "LoginAttribs" with "userName" and
"password"
I instert the LoginAttribs loginAttr obj in knowledgebase in A.java
WorkingMemory workingMemory = ruleBase.newStatefulSession();
LoginAttribs loginAttr = new LoginAttribs();
workingMemory.insert(loginAttr );
and change the rule in drl file like
rule "login_validation"
when
$lg : LoginAttribs ($uN: userName , $pwd:password)
userRole:UserRole() from hibernateSession.createQuery("select userRoles
from UserAccount ua where ua.name = :name AND ua.password =
:password").setProperties( {"name" : $uN , "password" : $pwd
}).list()
then
System.out.println( "--------------------The role " +
userRole.getRoleName()+" is owned by "+userRole.getAccounts());
end
And then this comes
Exception caught while executing action:
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction@1406eb6
[Error: unable to access property (null parent): createQuery]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:861)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:316)
at
org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:138)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:133)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at
org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:107)
at org.mvel2.MVEL.executeExpression(MVEL.java:995)
at
org.drools.base.dataproviders.MVELDataProvider.getResults(MVELDataProvider.java:91)
at org.drools.reteoo.FromNode.evaluateAndPropagate(FromNode.java:124)
at org.drools.reteoo.FromNode.assertLeftTuple(FromNode.java:104)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.doPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:145)
at
org.drools.reteoo.CompositeLeftTupleSinkAdapter.createAndPropagateAssertLeftTuple(CompositeLeftTupleSinkAdapter.java:57)
at
org.drools.reteoo.LeftInputAdapterNode.assertObject(LeftInputAdapterNode.java:142)
at
org.drools.reteoo.SingleObjectSinkAdapter.propagateAssertObject(SingleObjectSinkAdapter.java:42)
at org.drools.reteoo.ObjectTypeNode.assertObject(ObjectTypeNode.java:185)
at org.drools.reteoo.EntryPointNode.assertObject(EntryPointNode.java:146)
at org.drools.reteoo.Rete.assertObject(Rete.java:113)
at org.drools.reteoo.ReteooRuleBase.assertObject(ReteooRuleBase.java:218)
at
org.drools.reteoo.ReteooWorkingMemory$WorkingMemoryReteAssertAction.execute(ReteooWorkingMemory.java:291)
at
org.drools.common.AbstractWorkingMemory.executeQueuedActions(AbstractWorkingMemory.java:1486)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1051)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:1001)
at
org.drools.common.AbstractWorkingMemory.insert(AbstractWorkingMemory.java:788)
by commenting the insert statement in the java file it works fine
--
View this message in context:
http://n3.nabble.com/Call-class-method-from-LHS-of-a-rule-tp108383p519963...
Sent from the Drools - User mailing list archive at
Nabble.com.