AnsweredAssumed Answered

Configuring JTA with Activiti

Question asked by suad on Aug 21, 2011
Latest reply on Aug 23, 2011 by suad
I am trying to configure activiti (5.6) to use Bitronix as Transaction Manager through JtaProcessEngineConfiguration. I am using MySQL as a database. Currently I am running the application as a standalone. I am getting the below exception.


[2011-08-21 13:57:06,579] DEBUG main java.sql.PreparedStatement - ==>  Executing: select * from ACT_GE_PROPERTY where NAME_ = ?
[2011-08-21 13:57:06,579] DEBUG main java.sql.PreparedStatement - ==> Parameters: schema.version(String)
[2011-08-21 13:57:06,704] DEBUG main java.sql.ResultSet - <==    Columns: NAME_, VALUE_, REV_
[2011-08-21 13:57:06,704] DEBUG main java.sql.ResultSet - <==        Row: schema.version, 5.6, 1
[2011-08-21 13:57:06,767] ERROR main java.sql.Connection - Error calling Connection.setAutoCommit:
java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
   at bitronix.tm.resource.jdbc.JdbcConnectionHandle.setAutoCommit(JdbcConnectionHandle.java:177)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at bitronix.tm.resource.jdbc.BaseProxyHandlerClass.invoke(BaseProxyHandlerClass.java:63)
   at $Proxy0.setAutoCommit(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:52)
   at $Proxy1.setAutoCommit(Unknown Source)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:57)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:35)
   at org.apache.ibatis.executor.BaseExecutor.close(BaseExecutor.java:53)
   at org.apache.ibatis.executor.CachingExecutor.close(CachingExecutor.java:32)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.close(DefaultSqlSession.java:166)
   at org.activiti.engine.impl.db.DbSqlSession.close(DbSqlSession.java:440)
   at org.activiti.engine.impl.interceptor.CommandContext.closeSessions(CommandContext.java:154)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:126)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:59)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:77)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:280)
   at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:56)
   at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)
   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1414)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:245)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
   at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
   
[2011-08-21 13:57:06,767] DEBUG main bitronix.tm.BitronixTransactionManager - marking transaction as rollback only: a Bitronix Transaction with GTRID [737072696E672D62746D00000131EBC5ADDE00000000], status=ACTIVE, 1 resource(s) enlisted (started Sun Aug 21 13:57:06 GST 2011)
[2011-08-21 13:57:06,767] DEBUG main bitronix.tm.BitronixTransaction - changing transaction status to MARKED_ROLLBACK
[2011-08-21 13:57:06,767] DEBUG main bitronix.tm.journal.TransactionLogAppender - between 3590 and 3661, writing a Bitronix TransactionLogRecord with status=MARKED_ROLLBACK, recordLength=63, headerLength=28, time=1313920626767, sequenceNumber=3, crc32=1776255398, gtrid=737072696E672D62746D00000131EBC5ADDE00000000, uniqueNames=java/actdb
[2011-08-21 13:57:06,782] DEBUG main bitronix.tm.journal.TransactionLogAppender - disk journal appender now at position 3661
[2011-08-21 13:57:06,782] DEBUG main bitronix.tm.BitronixTransaction - transaction status is changing from ACTIVE to MARKED_ROLLBACK - executing 0 listener(s)
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'processEngine': FactoryBean threw exception on object creation; nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error closing transaction.  Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Cause: java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
### Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Cause: java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1414)
   at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:245)
   at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:190)
   at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1075)
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error closing transaction.  Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Cause: java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
### Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Cause: java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
   at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.close(DefaultSqlSession.java:169)
   at org.activiti.engine.impl.db.DbSqlSession.close(DbSqlSession.java:440)
   at org.activiti.engine.impl.interceptor.CommandContext.closeSessions(CommandContext.java:154)
   at org.activiti.engine.impl.interceptor.CommandContext.close(CommandContext.java:126)
   at org.activiti.engine.impl.interceptor.CommandContextInterceptor.execute(CommandContextInterceptor.java:49)
   at org.activiti.engine.impl.interceptor.JtaTransactionInterceptor.execute(JtaTransactionInterceptor.java:59)
   at org.activiti.engine.impl.interceptor.LogInterceptor.execute(LogInterceptor.java:33)
   at org.activiti.engine.impl.ProcessEngineImpl.<init>(ProcessEngineImpl.java:77)
   at org.activiti.engine.impl.cfg.ProcessEngineConfigurationImpl.buildProcessEngine(ProcessEngineConfigurationImpl.java:280)
   at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:56)
   at org.activiti.spring.ProcessEngineFactoryBean.getObject(ProcessEngineFactoryBean.java:32)
   at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
   … 7 more
Caused by: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Cause: java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:62)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.close(JdbcTransaction.java:35)
   at org.apache.ibatis.executor.BaseExecutor.close(BaseExecutor.java:53)
   at org.apache.ibatis.executor.CachingExecutor.close(CachingExecutor.java:32)
   at org.apache.ibatis.session.defaults.DefaultSqlSession.close(DefaultSqlSession.java:166)
   … 18 more
Caused by: java.sql.SQLException: autocommit is not allowed on a resource enlisted in a global transaction
   at bitronix.tm.resource.jdbc.JdbcConnectionHandle.setAutoCommit(JdbcConnectionHandle.java:177)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at bitronix.tm.resource.jdbc.BaseProxyHandlerClass.invoke(BaseProxyHandlerClass.java:63)
   at $Proxy0.setAutoCommit(Unknown Source)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.ibatis.logging.jdbc.ConnectionLogger.invoke(ConnectionLogger.java:52)
   at $Proxy1.setAutoCommit(Unknown Source)
   at org.apache.ibatis.transaction.jdbc.JdbcTransaction.resetAutoCommit(JdbcTransaction.java:57)
   … 22 more


I am using Spring to configure activiti as follow
<beans xmlns="http://www.springframework.org/schema/beans" 
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans   http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
                           http://www.springframework.org/schema/tx      http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

<tx:annotation-driven transaction-manager="transactionManager"/>


     <bean id="actDatasource" class="bitronix.tm.resource.jdbc.PoolingDataSource"  init-method="init" destroy-method="close">
      <property name="uniqueName" value="java/actdb" />
      <property name="minPoolSize" value="0" />
      <property name="maxPoolSize" value="10" />
      <property name="driverProperties">
         <props>
                   <prop key="user">root</prop>
                   <prop key="password"></prop>
                   <prop key="url">jdbc:mysql://localhost/activiti</prop>
         </props>
      </property>
      <property name="className" value="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource" />
      <property name="allowLocalTransactions" value="true" />
      <property name="enableJdbc4ConnectionTest" value="true"/>
    </bean>
   
        <bean id="JtaTransactionManager" class="org.springframework.transaction.jta.JtaTransactionManager"  >
      <property name="transactionManager" ref="bitronixTransactionManager" />
      <property name="userTransaction" ref="bitronixTransactionManager" />
   </bean>
   
   <bean id="btmConfig" factory-method="getConfiguration" class="bitronix.tm.TransactionManagerServices">
      <property name="serverId" value="spring-btm" />
   </bean>

   <!– create BTM transaction manager –>
   <bean id="bitronixTransactionManager"  factory-method="getTransactionManager" class="bitronix.tm.TransactionManagerServices" depends-on="btmConfig" destroy-method="shutdown" >
      <property name="transactionTimeout" value="6000000"/>
   </bean>
 
  <bean id="processEngineConfiguration" class="org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration">
    <property name="dataSource" ref="actDatasource" />
    <property name="transactionManager" ref="bitronixTransactionManager" />
    <property name="databaseSchemaUpdate" value="true" />
    <property name="jobExecutorActivate" value="false" />
    <property name="history" value="audit" />
  </bean>
 
   <bean id="processEngine" class="org.activiti.spring.ProcessEngineFactoryBean">
    <property name="processEngineConfiguration" ref="processEngineConfiguration" />
  </bean>
  
 
  <bean id="repositoryService" factory-bean="processEngine" factory-method="getRepositoryService" />
  <bean id="runtimeService" factory-bean="processEngine" factory-method="getRuntimeService" />
  <bean id="taskService" factory-bean="processEngine" factory-method="getTaskService" lazy-init="false"/>
  <bean id="historyService" factory-bean="processEngine" factory-method="getHistoryService" />
  <bean id="managementService" factory-bean="processEngine" factory-method="getManagementService" />
  <bean id="formService" factory-bean="processEngine" factory-method="getFormService" />
 
</beans>


any idea what is wrong..

Outcomes