title: Cannot make Bitronix manage my datasource/transactions in Spring Boot project
body: <p>I have been trying to make <code>JPAKnowledgeService</code> for about 3 days now, and I am quite close to giving up, it just seems as too much configuration and detail work for what it is/does. However,</p>
  
  <p>I had <a href="https://stackoverflow.com/questions/42226422/java-lang-nullpointerexception-when-creating-a-statefulknowledgesession-with-jpa">this problem</a> initially, which is gone away after I added</p>
  
  <pre><code>java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory
  </code></pre>
  
  <p>into my <code>jndi.properties</code> file, as the answer suggests. I was able to create a <code>StatefulKnowledgeSession</code> finally, and thought the work is over. But in drools chat, the same guy suggested that my transactions may have been being handled by Hibernate instead of Bitronix, which might make my persistence non-transactional altogether.</p>
  
  <p>And I guess he is right since whenever I tried to insert an <code>Object</code> into the Knowledge session and call <code>fireAllRules</code>, I was stuck at:</p>
  
  <pre><code>executing transaction with 0 enlisted resource
  </code></pre>
  
  <p>followed by:</p>
  
  <pre><code>transaction timed out: a Bitronix Transaction with GTRID [3132372E302E312E310000000000AFB9D800000006], status=MARKED_ROLLBACK, 0 resource(s) enlisted (started Thu Jan 01 05:11:56 EET 1970)
  </code></pre>
  
  <p>After that what I changed is; I updated my <code>persistence.xml</code> as follows:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" ?&gt;
  &lt;persistence xmlns="http://java.sun.com/xml/ns/persistence"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0"&gt;
      &lt;persistence-unit  name="org.jbpm.persistence.jpa" transaction-type="JTA"&gt;
          &lt;provider&gt;org.hibernate.jpa.HibernatePersistenceProvider&lt;/provider&gt;
          &lt;jta-data-source&gt;java:comp/env/jdbc/jbpm&lt;/jta-data-source&gt;
          &lt;class&gt;org.drools.persistence.info.SessionInfo&lt;/class&gt;
          &lt;properties&gt;
              &lt;property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/&gt;
              &lt;property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/&gt;
              &lt;property name="hibernate.max_fetch_depth" value="3"/&gt;
              &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt;
              &lt;property name="hibernate.show_sql" value="true" /&gt;
              &lt;property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.BTMTransactionManagerLookup" /&gt;
          &lt;/properties&gt;
      &lt;/persistence-unit&gt;
  &lt;/persistence&gt;
  </code></pre>
  
  <p>added this line into my <code>application.properties</code>:</p>
  
  <p><code>spring.datasource.jndi-name=java:comp/env/jdbc/jbpm</code></p>
  
  <p>and gave a jndi name to my datasource for embedded tomcat by following <a href="https://stackoverflow.com/questions/24941829/how-to-create-jndi-context-in-spring-boot-with-embedded-tomcat-container">these instructions</a>.</p>
  
  <p>and the error came back:</p>
  
  <pre><code>Caused by: java.lang.NullPointerException: null
      at org.drools.persistence.jta.JtaTransactionManager.getStatus(JtaTransactionManager.java:273) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
      at org.drools.persistence.jpa.AbstractPersistenceContextManager.getApplicationScopedEntityManager(AbstractPersistenceContextManager.java:78) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
      at org.drools.persistence.jpa.JpaPersistenceContextManager.getApplicationScopedPersistenceContext(JpaPersistenceContextManager.java:55) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
      at org.drools.persistence.SingleSessionCommandService.&lt;init&gt;(SingleSessionCommandService.java:103) ~[drools-persistence-jpa-6.5.0.Final.jar:6.5.0.Final]
      ... 43 common frames omitted
  </code></pre>
  
  <p>The tables related to <code>JPAKnowledgeService</code> are created in the database, so I guess my JNDI registration is successful, but I don't seem to be able to find Bitronix as my transaction manager since <code>JtaTransactionManager</code> seems as null. What am I doing wrong? I am frustrated and clueless.</p>