1 2 Previous Next 15 Replies Latest reply on Aug 13, 2014 10:47 PM by linuslan

    Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"

    arif.mohammed

      Hi,

       

         I am trying to integrate jBPM6.1.0.Beta2 in my web application by using spring integration module (kie-spring-6.1.0.Beta1) and it is failing during start up with the message "Transaction is already completed - do not call commit or rollback more than once per transaction". Not sure what is the issue with this configuration, I am attaching both spring-context.xml and exception stack trace.

        • 2. Re: Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
          arif.mohammed

          Ok to give you more update on this ...

           

          My Tech Stack for using jBPM6 in embedded mode

               1) jBPM-6.1.0.Beta2 and kie-spring-6.1.0.Beta2 (Both are deployed as jBoss module library, module.xml attached)

               2) jBoss7.1.1.Final App server

               3) spring-3.2.0.Release (using spring webflow and mvc)

               4) Oracle DB

          As you can see from above post I was using CustomScope in spring-context.xml, I did this intentionally so that I can test this piece of code by taking it out of the container so that I can check transactions behaviour. Please note that I am using Srping @Tranasaction in my code. Since there are lots of problems and I don't know what is happening so I tested it by deploying my war in jBoss7.1.1.Final. I am attaching latest spring-context.xml and persistence.xml and here is what happened.

           

              Problem1: Deployment was failing since jBPM6 is complaining about CDI dependencies. By going through this thread (Anybody have an example of how to embed the JBPM 6 Engine in a Spring application?) I see there are some issues with jBPM6 in non CDI environment so I have added following fragment in jboss-deployment-structure.xml

                  <exclusions>        

                    <module name="javaee.api" /> 

                    <module name="org.javassist" /> 

                    <module name="org.jboss.interceptor" /> 

                    <module name="org.jboss.as.weld" /> 

                    <module name="org.jboss.weld.core" /> 

                    <module name="org.jboss.weld.api" /> 

                    <module name="org.jboss.weld.spi" />

                  </exclusions>     

           

                But Still it complains about java.lang.NoClassDefFoundError: javax/enterprise/inject/Instance

            

             So to keep going I have added following fragment in jBPM libraries module.xml (Though my application is not EE compatible) and removed the above exclusions from my jboss-deployment-structure.xml

                  <dependencies>

                    <module name="javax.enterprise.api"/>

                  </dependencies>

           

          , the problem was solved by adding above dependency in my jBPM library.

           

            Problem2: Once the above problem is solved I was successfully able to deploy my webapp in app server but now the real problem is with transaction manager which is as follows.

                java.lang.ClassCastException: org.springframework.transaction.jta.JtaTransactionManager cannot be cast to org.drools.persistence.TransactionManager

               I don't know why the given transaction manager(i.e, org.springframework.transaction.jta.JtaTransactionManager) is not respected. The problem lies at the following statement in org.jbpm.runtime.manager.impl.AbstractRuntimeManager.java

           

              protected TransactionManager getTransactionManager() {

                  TransactionManager tm = (TransactionManager) environment.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER);

                  if (tm == null) {

                    tm = new JtaTransactionManager(null, null, null);

                  }

                  return tm;

              }

           

             I am attaching fragment of code for ProcessService.java from where the transaction is triggered and the ProcessUtility.java (helper class to interact with jBPM)

          • 3. Re: Re: Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
            arif.mohammed

            I tried to do it programatically instead of doing from spring configuration but now its failing in different place whose stacktrace follows . I did it as follows in my ProcessUtility.java

             

            @Override
            public void afterPropertiesSet() throws Exception {
            KieServices kservices = KieServices.Factory.get();
            UserGroupCallbackImpl groupCallBack = new UserGroupCallbackImpl();
            KieSpringTransactionManager springTrxMgr = new KieSpringTransactionManager(txMgr);
            RuntimeEnvironment runtimeEnv = RuntimeEnvironmentBuilder.Factory.get()
            .newDefaultBuilder()
            .addAsset(
            kservices.getResources().newClassPathResource("workflows/approval-process.bpmn2"),
            ResourceType.BPMN2)
                .addEnvironmentEntry(EnvironmentName.TRANSACTION_MANAGER, springTrxMgr)
                .entityManagerFactory(emf).userGroupCallback(groupCallBack)
            .get();
            runtimeManager = RuntimeManagerFactory.Factory.get().newPerProcessInstanceRuntimeManager(runtimeEnv);
            }

             

             

            Caused by: java.lang.IllegalStateException: java.lang.reflect.InvocationTargetException

              at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:164) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:70) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.newKieSession(KnowledgeStoreServiceImpl.java:39) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.kie.internal.persistence.jpa.JPAKnowledgeService.newStatefulKnowledgeSession(JPAKnowledgeService.java:121) [kie-internal-6.1.0.Beta1.jar:6.1.0.Beta1]

              at org.jbpm.runtime.manager.impl.factory.JPASessionFactory.newKieSession(JPASessionFactory.java:42) [jbpm-runtime-manager-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager.init(PerProcessInstanceRuntimeManager.java:292) [jbpm-runtime-manager-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newPerProcessInstanceRuntimeManager(RuntimeManagerFactoryImpl.java:104) [jbpm-runtime-manager-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.jbpm.runtime.manager.impl.RuntimeManagerFactoryImpl.newPerProcessInstanceRuntimeManager(RuntimeManagerFactoryImpl.java:95) [jbpm-runtime-manager-6.1.0.Beta2.jar:6.1.0.Beta2]

              at com.xyz.ras.util.ProcessUtility.afterPropertiesSet(ProcessUtility.java:92) [classes:]

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1545) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]

              at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1483) [spring-beans-3.2.0.RELEASE.jar:3.2.0.RELEASE]

              ... 59 more

            Caused by: java.lang.reflect.InvocationTargetException

              at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.7.0_45]

              at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.7.0_45]

              at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) [rt.jar:1.7.0_45]

              at java.lang.reflect.Constructor.newInstance(Unknown Source) [rt.jar:1.7.0_45]

              at org.drools.persistence.jpa.KnowledgeStoreServiceImpl.buildCommandService(KnowledgeStoreServiceImpl.java:150) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              ... 69 more

            Caused by: java.lang.ClassCastException: org.kie.spring.persistence.KieSpringTransactionManager cannot be cast to javax.transaction.TransactionManager

              at org.drools.persistence.jta.JtaTransactionManager.<init>(JtaTransactionManager.java:85) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.drools.persistence.SingleSessionCommandService.initTransactionManager(SingleSessionCommandService.java:322) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              at org.drools.persistence.SingleSessionCommandService.<init>(SingleSessionCommandService.java:114) [drools-persistence-jpa-6.1.0.Beta2.jar:6.1.0.Beta2]

              ... 74 more

            • 5. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
              arif.mohammed

              Ok alright I resolved the issue. Couple of things which are noteworthy which can help others if they end up in this issue ....

               

                 Problem1: Still it remains same, I need to add jars related to CDI (please check updated module.xml for <module name="javax.enterprise.api"/> )

                 Problem2: If you check exception.txt.zip attached to this thread you will find an invalid sql statement which is as follows, I did not noticed this issue. But the error message is completely misleading.

                  Hibernate: select taskimpl0_.id as col_0_0_, deadlineim1_.id as col_1_0_, deadlineim1_.deadline_date as col_2_0_ from Task taskimpl0_, Deadline deadlineim1_ where taskimpl0_.archived=0 and (deadlineim1_.id in (select startdeadl2_.id from Deadline startdeadl2_ where taskimpl0_.id=startdeadl2_.Deadlines_StartDeadLine_Id)) and deadlineim1_.escalated=0 order by deadlineim1_.deadline_date

               

                  Actually there is no "ID" in Task table. I have executed the DDL statements came with the jBPM6 installation as mentioned in documentation (Chapter 3. jBPM Installer)

                  Seems tobe the DDL statements provided with distribution is wrong I see instead of Task.ID in DDL statement it was Task.TaskId. I dropped all tables and recreated with the hibernate option (hibernate.hbm2ddl.auto) . Will some one from jBPM is taking care of this ?

               

                Problem3: I was using jars related to jBPM6.1.0.Beta2 and kie-spring-6.1.0.Beta2.jar. I just used jBPM6.0.1.Final and kie-spring-6.1.0.Beta2.jar (for spring integration) and it started working.

               

                Problem4: It seems to be there is a bug in RuntimeEnvironmentBuilder.schedulerService and it got fixed in version 6.1.0.Beta2. It was complaining about "Argument is not of type GlobalSchedulerService". I took the following code from 6.1.0.Beta2 and built jbpm-runtime-manager-6.0.1.Final. I hope until 6.1.0 is released there will be no issue with the following fix.

               

                  public RuntimeEnvironmentBuilder schedulerService(Object globalScheduler) {

                    if (globalScheduler == null) {

                          return this;

                      }

                      if (!(globalScheduler instanceof GlobalSchedulerService)) {

                      throw new IllegalArgumentException("Argument is not of type GlobalSchedulerService");

                      }

                      this.runtimeEnvironment.setSchedulerService((GlobalSchedulerService) globalScheduler);

                      return this;

                  }

               

                Hopefully the transactions problem will not bug me again and will not take over my sleep

              • 6. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                swiderski.maciej

                Arif,

                 

                when it comes do DDL there was an issue with identifier of some columns which was reported as jira and fixed in 6.1.0. So best would be to not nix versions you're using and if you are on 6.1.0-Beta2 then use all artifacts from that version as mixing various versions can lead to weird errors.

                 

                Problem 1, do you have any stack trace that complains about missing CDI api dependencies, that should not be the case unless you have a code that tries to interact with CDI.

                Problem 2, use DDL scripts from 6.1.0-Beta2 instead and the identifiers should be properly configured

                Problem 3, do you have any issues with configuring it all in spring xml? And again, please stick to single version

                Problem 4, might not be seen as a bug but rather protection about incorrect usage as you should not invoke builder methods and pass null objects

                 

                Glad you had made it to work, good work! Let me know if there are any other issues with 6.1.0-Beta2 so we can address it before it goes out as final.

                 

                HTH

                • 7. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                  arif.mohammed

                  Thanks Maciej for the reply.

                   

                       Iam successfully able to configure it in the container and it let me keep going with my project i.e, in jBoss. But I still have problems using it in standalone application. I will create a test case/simple eclipse project so that you can run that application and help me.

                  • 8. Re: Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                    arif.mohammed

                    Hi Maciej, I have attached my eclipse project. As I said there are some issues running it as a standalone application, Iam getting the following exception. You can import the project in eclipse, add oracle DB details in jta-emf-spring.xml and add the dependency jars as per the .classpath file. Please let me know if you need any other information.

                     

                    Apr 22, 2014 11:09:23 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh

                    INFO: Refreshing org.springframework.context.support.ClassPathXmlApplicationContext@43762332: startup date [Tue Apr 22 11:09:23 MDT 2014]; root of context hierarchy

                    Apr 22, 2014 11:09:23 AM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions

                    INFO: Loading XML bean definitions from class path resource [jta-emf-spring.xml]

                    Apr 22, 2014 11:09:23 AM org.springframework.orm.jpa.persistenceunit.PersistenceUnitReader determinePersistenceUnitRootUrl

                    INFO: persistence-jta.xml should be located inside META-INF directory; cannot determine persistence unit root URL for class path resource [persistence-jta.xml]

                    Apr 22, 2014 11:09:23 AM org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean createNativeEntityManagerFactory

                    INFO: Building JPA container EntityManagerFactory for persistence unit 'org.jbpm.persistence.spring.jta'

                    0    [main] WARN  bitronix.tm.Configuration  - cannot get this JVM unique ID. Make sure it is configured and you only use ASCII characters. Will use IP address instead (unsafe for production usage!).

                    Apr 22, 2014 11:09:27 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons

                    INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@8845448: defining beans [jbpmEMF,jbpmDS,BitronixTransactionManager,jbpmTxManager,process,runtimeEnvironment,runtimeManager,logService]; root of factory hierarchy

                    Apr 22, 2014 11:09:27 AM org.springframework.transaction.jta.JtaTransactionManager checkUserTransactionAndTransactionManager

                    INFO: Using JTA UserTransaction: a BitronixTransactionManager with 0 in-flight transaction(s)

                    Apr 22, 2014 11:09:27 AM org.springframework.transaction.jta.JtaTransactionManager checkUserTransactionAndTransactionManager

                    INFO: Using JTA TransactionManager: a BitronixTransactionManager with 0 in-flight transaction(s)

                    Hibernate: select SESSIONINFO_ID_SEQ.nextval from dual

                    Hibernate: insert into SessionInfo (lastModificationDate, rulesByteArray, startDate, OPTLOCK, id) values (?, ?, ?, ?, ?)

                    3170 [main] WARN  bitronix.tm.twopc.Preparer  - executing transaction with 0 enlisted resource

                    Hibernate: delete from SessionInfo where id=? and OPTLOCK=?

                    Hibernate: select contextmap0_.KSESSION_ID as col_0_0_ from ContextMappingInfo contextmap0_, ProcessInstanceInfo processins1_ inner join EventTypes eventtypes2_ on processins1_.InstanceId=eventtypes2_.InstanceId where eventtypes2_.element='timer' and contextmap0_.CONTEXT_ID=processins1_.InstanceId and contextmap0_.OWNER_ID=?

                    Hibernate: select SESSIONINFO_ID_SEQ.nextval from dual

                    Hibernate: insert into SessionInfo (lastModificationDate, rulesByteArray, startDate, OPTLOCK, id) values (?, ?, ?, ?, ?)

                    3251 [main] WARN  bitronix.tm.twopc.Preparer  - executing transaction with 0 enlisted resource

                    3254 [main] WARN  bitronix.tm.twopc.Preparer  - executing transaction with 0 enlisted resource

                    Hibernate: select taskimpl0_.id as col_0_0_, deadlineim1_.id as col_1_0_, deadlineim1_.deadline_date as col_2_0_ from Task taskimpl0_, Deadline deadlineim1_ where taskimpl0_.archived=0 and (deadlineim1_.id in (select startdeadl2_.id from Deadline startdeadl2_ where taskimpl0_.id=startdeadl2_.Deadlines_StartDeadLine_Id)) and deadlineim1_.escalated=0 order by deadlineim1_.deadline_date

                    Hibernate: select taskimpl0_.id as col_0_0_, deadlineim1_.id as col_1_0_, deadlineim1_.deadline_date as col_2_0_ from Task taskimpl0_, Deadline deadlineim1_ where taskimpl0_.archived=0 and (deadlineim1_.id in (select enddeadlin2_.id from Deadline enddeadlin2_ where taskimpl0_.id=enddeadlin2_.Deadlines_EndDeadLine_Id)) and deadlineim1_.escalated=0 order by deadlineim1_.deadline_date

                    Exception in thread "main" java.lang.ClassCastException: org.springframework.transaction.jta.JtaTransactionManager cannot be cast to org.drools.persistence.TransactionManager

                      at org.jbpm.runtime.manager.impl.AbstractRuntimeManager.getTransactionManager(AbstractRuntimeManager.java:208)

                      at org.jbpm.runtime.manager.impl.AbstractRuntimeManager.registerDisposeCallback(AbstractRuntimeManager.java:116)

                      at org.jbpm.runtime.manager.impl.PerProcessInstanceRuntimeManager.getRuntimeEngine(PerProcessInstanceRuntimeManager.java:113)

                      at org.kie.spring.jbpm.JTAEntityManagerFactorySpringTest.main(JTAEntityManagerFactorySpringTest.java:52)

                    • 9. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                      arif.mohammed

                      Hi Maciej,

                       

                           If I use same version of jars i.e, jBPM6.1.0.Beta2 and kie-spring-6.1.0.Beta2.jar Problem3 remains same even if I am deploying in jBoss. I am getting the same exception could you please help me what's wrong with the configuration. It is a very simple configuration as it was used in the test cases.

                       

                      14:07:30,381 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) java.lang.ClassCastException: org.springframework.transaction.jta.JtaTransactionManager cannot be cast to org.drools.persistence.TransactionManager

                      14:07:30,383 ERROR [stderr] (http-localhost-127.0.0.1-8080-2) at org.jbpm.runtime.manager.impl.AbstractRuntimeManager.getTransactionManager(AbstractRuntimeManager.java:208)

                      • 10. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                        arif.mohammed

                        hmm.. Test cases for spring-kie module for version 6.1.0.Beta2 are failing due to the above reason. By the way what is the road map for release of 6.1.0 ?

                        • 11. Re: Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                          arif.mohammed

                          Hi Maciej,

                           

                              It is clearly a bug in version 6.1.0.Beta2. Spring transaction manager can't be used to integrate with jBPM6.x. Is it possible for you to provide a fix so that I can keep going with this version. If this is not possible I have to apply the patches to version 5.4.0.Final. It would be great help for me if you can provide a fix or point me to some alternative so that I can use jBPM6 with spring (configuration programatically is also fine ) for the time being until version 6.1 is released.

                          • 12. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                            swiderski.maciej

                            I believe I already fixed it sometime ago, though it might be an issue in Beta2, do you mind checking with latest master (6.1.0-SNAPSHOT)?

                            I am still off work but will look into it tomorrow. If the issue is still there in master.

                             

                            HTH

                            1 of 1 people found this helpful
                            • 13. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                              swiderski.maciej

                              I confirm that all spring integration tests are working as expected on master (6.1.0-SNAPSHOT)

                              • 14. Re: Spring integration with jBPM6.1.0.Beta2 is failing with message "Transaction is already completed - do not call commit or rollback more than once per transaction"
                                arif.mohammed

                                Hi Maciej. I was able to use 6.1.0.SNAPSHOT and able to integrate spring with master and as of now I don't see any issues with transactions. However I see 2 test cases are failing as below I observed the same with 6.0.1.Final, not sure how it effects.

                                 

                                Results :

                                Failed tests:

                                  KContainerInjectionTest.testSetterKContainer:62 null

                                  KContainerInjectionTest.testKContainer:52 null

                                Tests run: 90, Failures: 2, Errors: 0, Skipped: 2

                                [INFO] ------------------------------------------------------------------------

                                [INFO] BUILD FAILURE

                                [INFO] ------------------------------------------------------------------------

                                1 2 Previous Next