Thx. I now understand the part about the rule being fired for all customers
in memory. However, how do I achieve this on customer signup?
Given a TN in real time, I need to look up in the database if it is already
existing and if balance is greater than 0. If so, then do not allow signup.
btw, "hibernateSession.createQuery" expression validated in guvnor without
any problems. I had to declare hibernateSession as a global and set it in
the execution server. It actually fires also and I do nto see any errors but
I can't see the results anywhere.
Greg Barton wrote:
First off, the query should be:
from Customers where TN = :tn and balance > 0
And that would be only if you mapped the tn property to the name "TN". HQL
queries are case sensitive when it comes to property names:
http://www.hibernate.org/hib_docs/v3/reference/en-US/html_single/#queryhq...
Second, I don't know if that whole "hibernateSession.createQuery"
expression would compile in a DRL file. Have you tried it? Anyone?
Finally, this rule will fire for every Customer in working memory and look
up a matching Customer in the database. Seems a bit inneficient,
especially if you have many rules of this type. Would it be possible to
load the Customer from the database and just insert it into working memory
with it's "balance" property already set? That would be far simpler.
Then the rule would be:
global org.hibernate.Session hibernateSession;
when
cust1:Customer(balance > 0)
then
cust1.setIsAllowed(false);
hibernateSession.save(cust1);
end
(Ignoring the transaction management, here.)
You could even skip the save() on the hibernate session in the rule
action. You could keep the hibernate session open and save the Customers
when you've completed all changes.
--
View this message in context:
http://www.nabble.com/Guvnor%2C-database-and-rule-language-tp22810206p228...
Sent from the drools - user mailing list archive at
Nabble.com.