Facts from database - Hibernate configuration

829 views
Skip to first unread message

Jean-philippe Defrance

unread,
May 26, 2015, 7:50:18 AM5/26/15
to drools...@googlegroups.com
Hello,

I am using KIE Drools Workbench 6.0.2 deployed on a Tomcat 7.0 server on Windows. I have deployed the execution server on the same Tomcat server. I can successfully execute and test rules that I create through the web editor.

I would like to execute rules based on facts which are stored in a database (postgres). So far I just can't make it work, and I believe I am missing something in the setup

My understanding is that to do so, I can configure Hibernate and Bitronix Transation Manager to map facts classes to the database, so here is what I did:
- Added a new datasource in TOMCAT_HOME\conf\resources.properties
- Added a new persistence unit with reference to the datasource in TOMCAT_HOME\webapps\drools\WEB-INF\classes\META-INF\persistence.xml
- Added annotations in the data object source code:
import javax.persistence.*;
@PersistenceContext(name="org.csb.domain")
@Entity
@Table(name="ServiceOfferings")
And also the @Id on the Id of the entity.

That's it, but the rule does not trigger even though the condition is met (tested using a test case), and I don't see anything in the logs. I have seen on the web that some people create a hibernate session and pass it as a global variable to the rule. That being said I am not sure in which file I should put that (if it's required).

Could anyone please help ?

Thanks,

Mark Proctor

unread,
May 26, 2015, 12:40:30 PM5/26/15
to drools...@googlegroups.com
This sounds more like a hibernate/tomcat/bitronix Q, than a Drools one. Maybe try on the hibernate mailing list?

Drools just works with pojos, if it’s a pojo it’ll work. Maybe first assert that hibernate is loading your objects correctly, before inserting.

Either way there is not enough information for us to help you further here on the Drools side.

Mark
--
You received this message because you are subscribed to the Google Groups "Drools Setup" group.
To unsubscribe from this group and stop receiving emails from it, send an email to drools-setup...@googlegroups.com.
To post to this group, send email to drools...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/drools-setup/badaa425-08e3-4d2c-aab3-505a123746bf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jean-philippe Defrance

unread,
May 27, 2015, 6:16:48 AM5/27/15
to drools...@googlegroups.com
Hello Mark,

thanks for your reply.

My understanding is that Drools internally is already using hibernate, so maybe I was missing a configuration file, hence my question here.

Actually I am not yet inserting any objects because I am not sure where to put it. For instance if I look at what is described here:

I am wondering where to put the code to open the hibernate session because I don't have a standalone java code, I only have the data objects and the rules.

Mark Proctor

unread,
May 27, 2015, 9:11:47 AM5/27/15
to drools...@googlegroups.com
On 27 May 2015, at 11:16, Jean-philippe Defrance <jp.de...@gmail.com> wrote:

Hello Mark,

thanks for your reply.

My understanding is that Drools internally is already using hibernate, so maybe I was missing a configuration file, hence my question here.
We have a JPA module for serializing the session. But that is not what you are doing, so it is not related. We don’t use JPA or hibernate outside of that.


Actually I am not yet inserting any objects because I am not sure where to put it. For instance if I look at what is described here:

That is showing how to set a hibernate session, that you create, as a global. And then how to iterate the results of a hibernate query, using ‘from’. ‘from’ will not insert the objects, it will iterate them local to that rule, and fire for just that rule.

I am wondering where to put the code to open the hibernate session because I don't have a standalone java code, I only have the data objects and the rules.
you need to do what he does in that snippet, set it as a global.

Jean-philippe Defrance

unread,
May 28, 2015, 8:46:24 AM5/28/15
to drools...@googlegroups.com
Thank you Mark.

How do I set it as global? The only two files I have are the data object file and the rule file. The final goal is to execute this trough an API call to the execution server.

Mark Proctor

unread,
May 28, 2015, 4:58:37 PM5/28/15
to drools...@googlegroups.com
You an init rule, a rule with no LHS, to set the global value (see docs for setGlobal). You can access a static java helper method to get the hibernate session for you.

Mark

shivu shiva shivraj

unread,
Apr 20, 2016, 6:32:56 AM4/20/16
to Drools Setup

HOW TO GET HIBERNATE SESSION  INSIDE DROOLS WORKBENCH?
Reply all
Reply to author
Forward
0 new messages