-
1. Re: Drools (JBoss Rules) Hibernate Query and EntityManager
gavin.king Jul 19, 2007 10:22 AM (in response to damianharvey)The current version of Seam in CVS has a Drools GlobalResolver that lets you use any Seam context variable as a drools global, completely transparently :-)
-
2. Re: Drools (JBoss Rules) Hibernate Query and EntityManager
ellenzhao Jul 19, 2007 11:24 AM (in response to damianharvey)@damianharvey:
You can tie Seam and Drools like this:
In your conversation bean, you say:... @In private RuleBase myRuleBase; // you must have already this rule base defined in your component.xml. Please refer to Seam manual. ... public void eatCheese(){ // you can also use stateful rule session here. Please refer to Drools' manual StatelessSession ruleSession = myRuleBase.newStatelessSession(); ruleSession.setGlobal("entityManager", entityManager); ruleSession.setGlobal("anotherResource", anotherResource); ... ruleSession.execute(cheeseList); } ...
In your .drl file, you can define the entityManager as global so all your rules in that rule package can share this single entityManager. You can ask entityManager to fetch the data you want at LHS and do things like entityManager.flush() at RHS.
Enjoy!
Ellen -
3. Re: Drools (JBoss Rules) Hibernate Query and EntityManager
damianharvey Jul 19, 2007 12:15 PM (in response to damianharvey)Thanks to you both for your replies. I'll try it out.
Cheers,
Damian. -
4. Re: Drools (JBoss Rules) Hibernate Query and EntityManager
ellenzhao Jul 19, 2007 12:16 PM (in response to damianharvey)Forgot to mention it's better not to mess your rule definition with things like persistence code or rendering code. It's better to do session.setGlobal("cheeseList", cheeseList); , let your rule engine use or modify the cheeseList. The modification is automatically visible to the conversation bean which passed this cheeseList to your rule session. The conversation bean should be the central controller/coordinator for all kinds of "engines" (stuff like jsf can be viewed as rendering engine, stuff like hibernate/JPA persisting engine, jBPM process engine, Drools rule engine....)and let your "engines" to manipulate the state space of your entity's. That said, inside each kind of "engines", it's best to see only entities around and a handle to the central controller, but not any dependencies to any other kind of "engine".
Ideally, the conversation bean should not manipulate the state space of any entity, but just pass entities around (read only!) to different engines. But this is not practical for applications that are not complex enough. -
5. Re: Drools (JBoss Rules) Hibernate Query and EntityManager
damianharvey Jul 20, 2007 3:50 AM (in response to damianharvey)Thanks Ellen. So would you advise not to use Database queries from within a rule then? In this case the query would be against a list of prices (possibly thousands). Is it better to read these in the Bean and pass the whole lot to Drools?
Regards,
Damian. -
6. Re: Drools (JBoss Rules) Hibernate Query and EntityManager
gavin.king Jul 20, 2007 4:20 AM (in response to damianharvey)Ask Mark Proctor that question in the Drools forum. I know he has been working on this.