[rules-users] Working memory - database synchronisation approach

Stephen Masters stephen.masters at me.com
Thu Mar 28 06:17:44 EDT 2013


That sounds like a decent design to me. I don't much like having persistence inside the rules.

The issue you have seems more related to the fact that you're executing the rules in a separate thread than your persistence design. I don't suppose you're actually spawning a thread from inside a JTA transaction in which to run your rules?

Steve


On 28 Mar 2013, at 08:46, riri <irina.adam at gmail.com> wrote:

> Hello everyone,
> 
> I am currently working on a Spring, Hibernate, Bitronix project and am
> trying to integrate Drools functionality. I have a set of JPA Entities that
> I can manage using Spring Data and Hibernate and I would like to use these
> entities as facts inside a StatefulKnowledgeSession. As I understand it, I
> need to have some mechanism of keeping the facts inside the working memory
> in sync with the database and what I mean by that is:
> 1. update the facts in working memory when they are changed from outside
> 2. update the facts in the database when a RHS part of a rule changes
> properties
> 
> This article  http://www.ibm.com/developerworks/java/library/j-drools5/
> <http://www.ibm.com/developerworks/java/library/j-drools5/>   gives some
> pointers on how to achieve 1. using AOP but in my case I do not have a
> global knowledge session to insert, I need to be able to create a knowledge
> base for each user of the application since each user will need to have his
> own set of rules independent from other users.
> 
> What would be the best practices for achieving the synchronisation?
> Currently for 1. I am updating the fact manually by retrieving the object
> and calling update from java code. For 2. I have a
> WorkingMemoryEventListener that is configured as a Spring @Component with
> autowired services that can perform CRUD actions on entities and which are
> called on objectUpdated.
> 
> I am new to all these technologies so I do not know if this is a good way to
> go. I have a unit test where a rule modifies a property and the object is
> updated in the database but if the Thread with the fireUntilHalt method is
> not paused, the test finishes and the JTA manager is shut down before the
> rules can fire and the transaction in the objectUpdated can be executed.
> 
> I would be very grateful for any insight from the more experienced users
> that have come across such requirements before.
> 
> Best regards
> 
> 
> 
> --
> View this message in context: http://drools.46999.n3.nabble.com/Working-memory-database-synchronisation-approach-tp4023094.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