<div dir="ltr">Hi Jean Philippe,<div><br></div><div>I have recently created a project to persist bpmn process using Spring & JPA / Hibernate. This config is working using kie-spring </div><div><br></div><div><a href="https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/spring-jbpm-persistence/src/main/resources/META-INF/spring/context.xml">https://github.com/cmoulliard/droolsjbpm-osgi-examples/blob/master/spring-jbpm-persistence/src/main/resources/META-INF/spring/context.xml</a><br>
</div><div><br></div><div>Regards,</div><div><br></div><div>Charles</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 22, 2014 at 8:00 PM, Steinmetz, Jean-Philippe <span dir="ltr"><<a href="mailto:jpsteinmetz@theworkshop.us.com" target="_blank">jpsteinmetz@theworkshop.us.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">Hello All,<div><br></div><div>I am trying to set up persistence for a standalone Drools (6.0.1.Final) application that uses JPA, Hibernate (4.3.5.Final) and Bitronix (2.1.4) via Spring (4.0.3.RELEASE).</div>
<div><br></div><div>On the persistence side everything appears to be set up correctly. For my Drools session I use a KieContainer to create a new stateful session using an environment set up with the EntityManagerFactory and TransactionManager set. The problem that I am experiencing however is that nothing is getting persisted to the database. I have poured over the docs at least two dozen times and searched the net for anything related.</div>
<div><br></div><div>Here is what my Spring context file looks like when creating the Drools session...</div><div><br></div><div><div> <bean id="kReleaseId" factory-bean="kieServices" factory-method="newReleaseId"></div>
<div> <constructor-arg index="0" value="groupId"/></div><div> <constructor-arg index="1" value="artifactId"/></div><div> <constructor-arg index="2" value="1.0-SNAPSHOT"/></div>
<div> </bean></div><div> <bean id="kContainer" factory-bean="kieServices" factory-method="newKieContainer"></div><div> <constructor-arg index="0" ref="kReleaseId"/></div>
<div> </bean></div><div> <bean id="kEnvironment" factory-bean="kieServices" factory-method="newEnvironment"></div><div> <constructor-arg index="0"></div>
<div> <map></div><div> <entry></div><div> <key><util:constant static-field="org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY"/></key></div>
<div> <ref bean="entityManagerFactory"/></div><div> </entry></div><div> <entry></div><div> <key><util:constant static-field="org.kie.api.runtime.EnvironmentName.TRANSACTION_MANAGER"/></key></div>
<div> <ref bean="jtaTransactionManager"/></div><div> </entry></div><div> </map></div><div> </constructor-arg></div><div> </bean></div>
<div> <bean id="kSession" factory-bean="kContainer" factory-method="newKieSession"></div><div> <constructor-arg index="0" ref="kEnvironment"/></div>
<div>
</bean></div></div><div><br></div><div>Since the application is standalone I execute fireAllRules on the session at a regular interval (I use this instead of fireUntilHalt as it dramatically reduces the CPU load on the machine). With each call I wrap it in a transaction. Thus, the code looks as follows:</div>
<div><br></div><div><div> while (!Thread.currentThread().isInterrupted()) {</div><div> // Start a new transaction<br></div><div> UserTransaction utx = utx = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");</div>
<div> utx.begin();</div><div><br></div><div> // Tick the session</div><div> kSession.fireAllRules();</div><div><br></div><div> // Close the transaction</div><div> utx.commit();</div><div>
<br></div><div> // Sleep so that other applications can use the CPU<br></div><div> try {</div><div> Thread.sleep(1);</div><div> } catch (InterruptedException e) {</div><div>
// When our sleep is interrupted it's because the executor wants us to shut down.</div><div> Thread.currentThread().interrupt();</div><div> }</div><div> }</div></div><div>
<br></div><div>When I inspect kSession in the debugger I can see the environment is properly set. I have tried digging down into the execute a bit but can't find any point at which the TransactionManager or EntityManagerFactory are used. As I said above I know Hibernate is set up correctly as well as Bitronix. I can see them working just fine in the logs and they definitely are hitting the database (and create tables for sessioninfo and workingmemory as they should). I just get nothing actually in the database stored, ever.</div>
<div><br></div><div>Any help here is appreciated. It seems like it should work but it just doesn't.</div><div><br></div><div>Thanks in advance,</div><div><br></div><div>Jean-Philippe Steinmetz</div></div>
</div><br></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>
Charles Moulliard</div><div>Apache Committer / Architect @RedHat</div><div>Twitter : @cmoulliard | Blog : <a href="http://cmoulliard.github.io" target="_blank"> http://cmoulliard.github.io</a></div><div><br></div></div>
</div>