Unfortunately there is a &quot;bug&quot; (it is not really a bug but an omission in the code) that hides the real exception going on. The piece of code giving you troubles is (SingleSessionCommandService.java lines 119 - 138):<div>


<br></div><div><div>    <i><font face="&#39;courier new&#39;, monospace">try {</font></i></div><div><i><font face="&#39;courier new&#39;, monospace">            this.txm.begin();</font></i></div>
<div><i><font face="&#39;courier new&#39;, monospace"> </font></i></div><div><i><font face="&#39;courier new&#39;, monospace">            //this.appScopedEntityManager.joinTransaction();</font></i></div>
<div><i><font face="&#39;courier new&#39;, monospace">            registerRollbackSync();</font></i></div><div><i><font face="&#39;courier new&#39;, monospace"><br></font></i></div>
<div><i><font face="&#39;courier new&#39;, monospace">            jpm.getApplicationScopedPersistenceContext().persist( this.sessionInfo );</font></i></div><div><i><font face="&#39;courier new&#39;, monospace"><br>
</font></i></div><div><i><font face="&#39;courier new&#39;, monospace">            this.txm.commit();</font></i></div><div><i><font face="&#39;courier new&#39;, monospace"><br>
</font></i></div><div><i><font face="&#39;courier new&#39;, monospace">        } catch ( Exception <b>t1</b> ) {</font></i></div><div><i><font face="&#39;courier new&#39;, monospace">            try {</font></i></div>
<div><i><font face="&#39;courier new&#39;, monospace">                <b>this.txm.rollback();</b></font></i></div><div><i><font face="&#39;courier new&#39;, monospace">            } catch ( Throwable t2 ) {</font></i></div>


<div><i><font face="&#39;courier new&#39;, monospace">               <b> throw new RuntimeException( &quot;Could not commit session or rollback&quot;,</b></font></i></div><div><b><i><font face="&#39;courier new&#39;, monospace">                                            t2 );</font></i></b></div>


<div><i><font face="&#39;courier new&#39;, monospace">            }</font></i></div><div><i><font face="&#39;courier new&#39;, monospace">            throw new RuntimeException( &quot;Could not commit session&quot;,</font></i></div>


<div><i><font face="&#39;courier new&#39;, monospace">                                        t1 );</font></i></div><div><i><font face="&#39;courier new&#39;, monospace">        }</font></i></div>
</div><div> </div><div>As you can see, when there is a problem in the body of the try-catch, drools tries to rollback the session. If the rollback itself fails, you get the exception &quot;Could not commit session or rollback&quot;, but the original exception (t1) is lost.</div>


<div>We already fixed a similar issue in SingleSessionCommandService#execute() and created a rollbackTransaction() method that logs the first exception if the session rollback fails. </div>
<div>So, the solution (not a solution but a hack to see what is really going on) is to use the same rollbackTransaction() method in the catch part. If you want to see the real exception, you will need to download drools-persistence-jpa sources from <a href="https://github.com/droolsjbpm/drools/tree/master/drools-persistence-jpa" target="_blank">https://github.com/droolsjbpm/drools/tree/master/drools-persistence-jpa</a> and debug through the lines I mentioned. Or you can wait us to patch the code ;)</div>


<div>For the records, this is the bug previously reported: <a href="https://issues.jboss.org/browse/JBRULES-2656" target="_blank">https://issues.jboss.org/browse/JBRULES-2656</a>. I will create a new one and link them together. </div>

<div><br></div><div>Best Regards,<br clear="all">
<br>XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX<br><br>Esteban Aliverti<br>- Developer @ <a href="http://www.plugtree.com" target="_blank">http://www.plugtree.com </a><br>- Blog @ <a href="http://ilesteban.wordpress.com" target="_blank">http://ilesteban.wordpress.com</a><br>



<br><br><div class="gmail_quote">On Tue, Mar 1, 2011 at 7:53 AM, odelyaholiday <span dir="ltr">&lt;<a href="mailto:odelyay@sintecmedia.com" target="_blank">odelyay@sintecmedia.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">


Hi!<br>
<br>
I am working already for 3 days, trying to configure bitronix with spring<br>
and drools.<br>
<br>
I defined<br>
<br>
1. persistence unit:<br>
<br>
&lt;persistence-unit name=&quot;org.drools.persistence.jpa&quot; transaction-type=&quot;JTA&quot;&gt;<br>
                &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;<br>
                &lt;jta-data-source&gt;jdbc/DS1&lt;/jta-data-source&gt;<br>
                &lt;class&gt;org.drools.persistence.info.SessionInfo&lt;/class&gt;<br>
<br>
&lt;class&gt;org.jbpm.persistence.processinstance.ProcessInstanceInfo&lt;/class&gt;<br>
         &lt;class&gt;org.drools.persistence.info.WorkItemInfo&lt;/class&gt;<br>
                &lt;exclude-unlisted-classes&gt;true&lt;/exclude-unlisted-classes&gt;<br>
                &lt;properties&gt;<br>
                        &lt;property name=&quot;hibernate.dialect&quot;<br>
value=&quot;org.hibernate.dialect.Oracle10gDialect&quot; /&gt;<br>
                        &lt;property name=&quot;hibernate.connection.autocommit&quot; value=&quot;false&quot; /&gt;<br>
                        &lt;property name=&quot;hibernate.max_fetch_depth&quot; value=&quot;3&quot; /&gt;<br>
                        &lt;property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot; /&gt;<br>
                        &lt;property name=&quot;hibernate.current_session_context_class&quot; value=&quot;jta&quot; /&gt;<br>
                        &lt;property name=&quot;hibernate.connection.driver_class&quot;<br>
value=&quot;oracle.jdbc.xa.client.OracleXADataSource&quot; /&gt;<br>
                        &lt;property name=&quot;hibernate.jndi.class&quot;<br>
value=&quot;bitronix.tm.jndi.BitronixInitialContextFactory&quot;/&gt;<br>
                        &lt;property name=&quot;hibernate.transaction.manager_lookup_class&quot;<br>
value=&quot;org.hibernate.transaction.BTMTransactionManagerLookup&quot; /&gt;<br>
                &lt;/properties&gt;<br>
        &lt;/persistence-unit&gt;<br>
<br>
2. in my application context:<br>
&lt;!--  Bitronix Transaction Manager embedded configuration --&gt;<br>
        &lt;bean id=&quot;oracleDataSource&quot;<br>
class=&quot;bitronix.tm.resource.jdbc.PoolingDataSource&quot;<br>
                init-method=&quot;init&quot; destroy-method=&quot;close&quot;&gt;<br>
                &lt;property name=&quot;className&quot;<br>
value=&quot;oracle.jdbc.xa.client.OracleXADataSource&quot; /&gt;<br>
                &lt;property name=&quot;uniqueName&quot; value=&quot;jdbc/DS1&quot; /&gt;<br>
                &lt;property name=&quot;maxPoolSize&quot; value=&quot;5&quot; /&gt;<br>
                &lt;property name=&quot;allowLocalTransactions&quot; value=&quot;true&quot; /&gt;<br>
                &lt;property name=&quot;testQuery&quot; value=&quot;SELECT 1 FROM DUAL&quot; /&gt;<br>
                &lt;property name=&quot;driverProperties&quot;&gt;<br>
                        &lt;props&gt;<br>
                                &lt;prop key=&quot;user&quot;&gt;myuser&lt;/prop&gt;<br>
                                &lt;prop key=&quot;password&quot;&gt;myuser&lt;/prop&gt;<br>
                                &lt;prop key=&quot;URL&quot;&gt;myurl&lt;/prop&gt;<br>
                        &lt;/props&gt;<br>
                &lt;/property&gt;<br>
        &lt;/bean&gt;<br>
<br>
<br>
        &lt;bean id=&quot;btmConfig&quot; factory-method=&quot;getConfiguration&quot;<br>
                class=&quot;bitronix.tm.TransactionManagerServices&quot;&gt;<br>
                &lt;property name=&quot;serverId&quot; value=&quot;spring-btm&quot; /&gt;<br>
        &lt;/bean&gt;<br>
<br>
<br>
        &lt;bean id=&quot;BitronixTransactionManager&quot;<br>
factory-method=&quot;getTransactionManager&quot;<br>
                class=&quot;bitronix.tm.TransactionManagerServices&quot; depends-on=&quot;btmConfig&quot;<br>
                destroy-method=&quot;shutdown&quot; /&gt;<br>
<br>
<br>
        &lt;bean id=&quot;JtaTransactionManager&quot;<br>
                class=&quot;org.springframework.transaction.jta.JtaTransactionManager&quot;&gt;<br>
                &lt;property name=&quot;transactionManager&quot; ref=&quot;BitronixTransactionManager&quot; /&gt;<br>
                &lt;property name=&quot;userTransaction&quot; ref=&quot;BitronixTransactionManager&quot; /&gt;<br>
        &lt;/bean&gt;<br>
        &lt;!-- end of Bitronix Transaction Manager embedded configuration --&gt;<br>
<br>
3. and in the code:<br>
EntityManagerFactory emf =<br>
Persistence.createEntityManagerFactory(&quot;org.drools.persistence.jpa&quot;);<br>
                Environment env = KnowledgeBaseFactory.newEnvironment();<br>
                env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);<br>
                env.set(EnvironmentName.GLOBALS, new MapGlobalResolver());<br>
                env.set(EnvironmentName.TRANSACTION_MANAGER,<br>
TransactionManagerServices.getTransactionManager());<br>
                ksession = JPAKnowledgeService.newStatefulKnowledgeSession(kbase, null,<br>
env);<br>
<br>
However in the last code I get:<br>
<br>
Caused by: java.lang.IllegalStateException:<br>
java.lang.reflect.InvocationTargetException<br>
        at<br>
org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:130)<br>
        at<br>
org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newStatefulKnowledgeSession(KnowledgeStoreServiceImpl.java:54)<br>
        at<br>
org.drools.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:109)<br>
        at<br>
com.mycompany.util.BookWorkflowUtilities.createSession(BookWorkflowUtilities.java:83)<br>
        at com.mycompany.util.BookWorkflowService.init(BookWorkflowService.java:62)<br>
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
        at<br>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
        at<br>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
        at java.lang.reflect.Method.invoke(Method.java:597)<br>
        at<br>
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)<br>
        at<br>
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)<br>
        at<br>
org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)<br>
        ... 29 more<br>
Caused by: java.lang.reflect.InvocationTargetException<br>
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)<br>
        at<br>
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)<br>
        at<br>
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)<br>
        at java.lang.reflect.Constructor.newInstance(Constructor.java:513)<br>
        at<br>
org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommanService(KnowledgeStoreServiceImpl.java:116)<br>
        ... 40 more<br>
Caused by: java.lang.RuntimeException: Could not commit session or rollback<br>
        at<br>
org.drools.persistence.SingleSessionCommandService.&lt;init&gt;(SingleSessionCommandService.java:133)<br>
        ... 45 more<br>
Caused by: java.lang.RuntimeException: Unable to rollback transaction<br>
        at<br>
org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:184)<br>
        at<br>
org.drools.persistence.SingleSessionCommandService.&lt;init&gt;(SingleSessionCommandService.java:131)<br>
        ... 45 more<br>
Caused by: java.lang.NullPointerException<br>
        at<br>
org.drools.persistence.jta.JtaTransactionManager.rollback(JtaTransactionManager.java:181)<br>
<font color="#888888"><br>
--<br>
View this message in context: <a href="http://drools-java-rules-engine.46999.n3.nabble.com/Caused-by-java-lang-NullPointerException-at-org-drools-persistence-jta-JtaTransactionManager-rollbac-tp2602190p2602190.html" target="_blank">http://drools-java-rules-engine.46999.n3.nabble.com/Caused-by-java-lang-NullPointerException-at-org-drools-persistence-jta-JtaTransactionManager-rollbac-tp2602190p2602190.html</a><br>



Sent from the Drools - User mailing list archive at Nabble.com.<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">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>
</font></blockquote></div><br></div>