<div dir="ltr">Hi Jean Philippe,<div><br></div><div>I have recently created a project to persist bpmn process using Spring &amp; 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">&lt;<a href="mailto:jpsteinmetz@theworkshop.us.com" target="_blank">jpsteinmetz@theworkshop.us.com</a>&gt;</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>    &lt;bean id=&quot;kReleaseId&quot; factory-bean=&quot;kieServices&quot; factory-method=&quot;newReleaseId&quot;&gt;</div>


<div>        &lt;constructor-arg index=&quot;0&quot; value=&quot;groupId&quot;/&gt;</div><div>        &lt;constructor-arg index=&quot;1&quot; value=&quot;artifactId&quot;/&gt;</div><div>        &lt;constructor-arg index=&quot;2&quot; value=&quot;1.0-SNAPSHOT&quot;/&gt;</div>


<div>    &lt;/bean&gt;</div><div>    &lt;bean id=&quot;kContainer&quot; factory-bean=&quot;kieServices&quot; factory-method=&quot;newKieContainer&quot;&gt;</div><div>        &lt;constructor-arg index=&quot;0&quot; ref=&quot;kReleaseId&quot;/&gt;</div>


<div>    &lt;/bean&gt;</div><div>    &lt;bean id=&quot;kEnvironment&quot; factory-bean=&quot;kieServices&quot; factory-method=&quot;newEnvironment&quot;&gt;</div><div>        &lt;constructor-arg index=&quot;0&quot;&gt;</div>


<div>            &lt;map&gt;</div><div>                &lt;entry&gt;</div><div>                    &lt;key&gt;&lt;util:constant static-field=&quot;org.kie.api.runtime.EnvironmentName.ENTITY_MANAGER_FACTORY&quot;/&gt;&lt;/key&gt;</div>


<div>                    &lt;ref bean=&quot;entityManagerFactory&quot;/&gt;</div><div>                &lt;/entry&gt;</div><div>                &lt;entry&gt;</div><div>                    &lt;key&gt;&lt;util:constant static-field=&quot;org.kie.api.runtime.EnvironmentName.TRANSACTION_MANAGER&quot;/&gt;&lt;/key&gt;</div>


<div>                    &lt;ref bean=&quot;jtaTransactionManager&quot;/&gt;</div><div>                &lt;/entry&gt;</div><div>            &lt;/map&gt;</div><div>        &lt;/constructor-arg&gt;</div><div>    &lt;/bean&gt;</div>


<div>    &lt;bean id=&quot;kSession&quot; factory-bean=&quot;kContainer&quot; factory-method=&quot;newKieSession&quot;&gt;</div><div>        &lt;constructor-arg index=&quot;0&quot; ref=&quot;kEnvironment&quot;/&gt;</div>

<div>
    &lt;/bean&gt;</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(&quot;java:comp/UserTransaction&quot;);</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&#39;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&#39;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&#39;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>