7 Replies Latest reply on Mar 27, 2014 5:52 AM by swiderski.maciej

    Why TransactionManager can't find JTA Transaction?

    buenavida

      My JBPM application runs in a virgo/tomcat server. I am using JBPM 6.0.1.

       

      Firstly I build the default RuntimeEnvironment:

           RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()

             .entityManagerFactory(entityManagerFactory)

             .userGroupCallback(userGroupCallback)

             .addAsset(resource, type)

             .get();

       

      When I want to create a singletonsession via RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment) the Exception

       

           java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

            at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:143)

            at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:67)

            at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:36)

            at org.kie.internal.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:121)

            at org.jbpm.runtime.manager.impl.factory.JPASessionFactory.newKieSession(JPASessionFactory.java:41)

            ...

           Caused by: java.lang.IllegalStateException: Unable to find transaction: Name [java:comp/UserTransaction] is not bound in this Context. Unable to find [java:comp].

            at org.drools.persistence.jta.JtaTransactionManager.findUserTransaction(JtaTransactionManager.java:140)

            at org.drools.persistence.jta.JtaTransactionManager.<init>(JtaTransactionManager.java:79)

            at org.drools.persistence.SingleSessionCommandService.initTransactionManager(SingleSessionCommandService.java:320)

            at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:112)

            ... 102 more

           Caused by: javax.naming.NameNotFoundException: Name [java:comp/UserTransaction] is not bound in this Context. Unable to find [java:comp].

            at org.apache.naming.NamingContext.lookup(NamingContext.java:820)

            at org.apache.naming.NamingContext.lookup(NamingContext.java:168)

            at javax.naming.InitialContext.lookup(InitialContext.java:392)

            at org.drools.persistence.jta.JtaTransactionManager.findUserTransaction(JtaTransactionManager.java:132)

            ... 105 more

      is thrown.

       

      Like described in the documentation I placed the file jndi.properties in the root classpath of my application.

      The content of the file is "java.naming.factory.initial=bitronix.tm.jndi.BitronixInitialContextFactory".

       

      So the structure of my JBPM app is:

      JPBM-Workflows-App

      |-src

      |-META-INF

        |-persistence.xml

      |-jndi.properties

       

      I don't want to use a jta-datasource and therefore i define databse settings inside persistence.xml. The content of persistence.xml looks like:

      <?xml version="1.0" encoding="windows-1252" ?>

      <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" xmlns="http://java.sun.com/xml/ns/persistence">

        <persistence-unit name="org.jbpm.domain" transaction-type="JTA">

        <provider>org.hibernate.ejb.HibernatePersistence</provider>

      <properties>

            <property name="javax.persistence.jdbc.driver" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>

            <property name="javax.persistence.jdbc.url" value="jdbc:sqlserver://localhost:1433;databaseName=PM;"/>

           

            <property name="javax.persistence.jdbc.user" value="PMUser" />

            <property name="javax.persistence.jdbc.password" value="1234567" />

         

            <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>

            <property name="hibernate.max_fetch_depth" value="3"/>

            <property name="hibernate.hbm2ddl.auto" value="update" />

            <property name="hibernate.show_sql" value="false" />

            <!-- BZ 841786: AS7/EAP 6/Hib 4 uses new (sequence) generators which seem to cause problems -->     

            <property name="hibernate.id.new_generator_mappings" value="false" />           

           

            <!-- Transaction Manager -->

            <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.BitronixJtaPlatform" />

            <property name="hibernate.jndi.class" value="bitronix.tm.jndi.BitronixInitialContextFactory"/>     

          </properties>          

      </persistence-unit>

      </persistence>

       

      Why jndi name java:comp/UserTransaction isn't rigistered? Who is responsible for registering that?

        • 1. Re: Why TransactionManager can't find JTA Transaction?
          buenavida

          The message "No default interceptor found of type org.jbpm.services.task.persistence.TaskTransactionInterceptor might be mssing jbpm-human-task-jpa module on classpath" appears immediate before the exception.

           

          I don't find a jar called called jbpm-human-task-jpa in  jbpm-6.0.1-Final-bin. Is this file missing?

          • 2. Re: Why TransactionManager can't find JTA Transaction?
            swiderski.maciej

            Take a look at steps required to configure kie workbench on tomcat that can be found here. Focus mainly at configuration of bitornix to make sure you provide JTA data source that is transactional and at the same time configure all JNDI objects such as UserTransaction, TransactionManager and TransactionSynchornizationRegistry.

             

            jbpm-human-task-jpa module is in 6.1.0 only but the code required for it to work is inside jbpm-human-task-core in 6.0.1 so all classes are in there. Most likely the root of the error is same - unable to look up UserTransaction.

             

            HTH

            • 3. Re: Why TransactionManager can't find JTA Transaction?
              buenavida

              It is also a possibility for me to use Container Managed Transactions.

              In chapter 8 transactions you describe to set the transactionmanager like

              Environment env = EnvironmentFactory.newEnvironment();

              env.set(EnvironmentName.ENTITY_MANAGER_FACTORY, emf);

              env.set(EnvironmentName.TRANSACTION_MANAGER, new ContainerManagedTransactionManager());

              env.set(EnvironmentName.PERSISTENCE_CONTEXT_MANAGER, new JpaProcessPersistenceContextManager(env));

               

              I build my runtime engine by the usual way:

               

                   RuntimeEnvironment environment = RuntimeEnvironmentBuilder.getDefault()

                     .entityManagerFactory(Persistence.createEntityManagerFactory("org.jbpm.domain"))

                     .userGroupCallback(userGroupCallback)

                     .addAsset(ResourceFactory.newClassPathResource(process), ResourceType.BPMN2)

                     .get();

                  

                   RuntimeManager manager = RuntimeManagerFactory.Factory.get().newSingletonRuntimeManager(environment);

                   RuntimeEngine runtime = manager.getRuntimeEngine(EmptyContext.get());

               

              Where can I set the TransactionManager if I use this configuration?

              • 4. Re: Why TransactionManager can't find JTA Transaction?
                swiderski.maciej

                use addEnvironmentEntry on the builder, next to addAsset, etc. Please note that there were recent fixes for RuntimeManager in CMT environment that are currently available only on master - soon there will be 6.1.0 beta released. See this jira.

                 

                HTH

                • 5. Re: Why TransactionManager can't find JTA Transaction?
                  buenavida

                  You have forgotten to insert the link for topic "configure kie workbench on tomcat". Can you post the link please?

                  • 6. Re: Why TransactionManager can't find JTA Transaction?
                    buenavida

                    The system I use has no Transaction manager registered (and it is not possible to register one. I found already a btm instruction for tomcat). I do not need user defined transactions.

                     

                    Is the only possibility to use container managed transactions? Or are there other ways?

                    • 7. Re: Why TransactionManager can't find JTA Transaction?
                      swiderski.maciej

                      jbpm requires JTA transactions to work properly with persistence. The only way to use local transactions (no JTA required) is when using spring.

                       

                      HTH