在使用Atomikos过程中遇到的一些问题,以作记录:
MySQL does not support TMJOIN
MySQL does not allow for joining an existing XA transaction branch, as mentioned here:http://dev.mysql.com/doc/refman/5.0/en/xa-restrictions.html - the consequence is that one transaction accessing the same MySQL multiple times can run into problems like this:
com.atomikos.datasource.ResourceException: resume for XID 192.168.162.50.tm0000100012192.168.162..tm1 raised -: invalid arguments were given for the XA operation
at com.atomikos.datasource.xa.XAResourceTransaction.resume(Unknown Source)
at com.atomikos.jdbc.ConnectionProxy.invoke(Unknown Source)
at $Proxy8.prepareStatement(Unknown Source)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:)
at org.hibernate.transaction.JTATransaction.commit(JTATransaction.java:)
[...]
A possible workaround might be to try and start TransactionsEssentials with the parametercom.atomikos.icatch.serial_jta_transactions set to false.
com.atomikos.icatch.serial_jta_transactions=false
Also, make sure to set the following property on the MySQL datasource:
pinGlobalTxToPhysicalConnection="true"
以上是Atomikos官方关于Mysql bug的一些说明,解决这个问题按照官方说明,我们可以在jta.properties或者transactions.properties里面添加com.atomikos.icatch.serial_jta_transactions=false这么一段,可能我姿势不正确,没起作用。第二种方法是在Mysql的XADataSource的pinGlobalTxToPhysicalConnection设置为true,这可难办了,我使用的是druid的数据源,好像没有pinGlobalTxToPhysicalConnection这个的属性吧?苦恼了一段时间,查了一些资料都没有发现解决办法,突然灵机一动,试一下在url后缀加上这段东西,没想到真行了。
jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&pinGlobalTxToPhysicalConnection=true
MyBatis不能回滚事务?
2016-10-24 11:07:04,458 INFO [com.atomikos.datasource.xa.XAResourceTransaction] - XAResource.end ( 31302E3232382E37352E3132352E746D30303030313030303134:31302E3232382E37352E3132352E746D31 , XAResource.TMSUCCESS ) on resource apikore represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection@12a8ee2
2016-10-24 11:07:04,462 INFO [com.atomikos.datasource.xa.XAResourceTransaction] - XAResource.rollback ( 31302E3232382E37352E3132352E746D30303030313030303134:31302E3232382E37352E3132352E746D31 ) on resource apikore represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4SuspendableXAConnection@12a8ee2
2016-10-24 11:07:04,466 INFO [com.atomikos.icatch.imp.CompositeTransactionImp] - rollback() done of transaction 127.0.0.1.tm0000100014
检查一下控制台是否有着段输出,如果有,那么应该是回滚成功的。如果你断点spring的TransactionManager确定事务应经启用的情况下,出错了却没有回滚,请检查一下,事务设置是否带有rollback-for="Exception"
<tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
Connection pool exhausted - try increasing 'maxPoolSize'
错误:
[ERROR][-- ::,][org.hibernate.engine.jdbc.spi.SqlExceptionHelper]Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
[ERROR][-- ::,][org.apache.struts2.dispatcher.Dispatcher]Exception occurred during processing request: Could not open connection
在AtomikosDataSourceBean配置添加如下代码:
<property name="minPoolSize" value="5" />
<property name="maxPoolSize" value="20" />
<property name="borrowConnectionTimeout" value="60" />
Error in recovery
错误:
[ERROR][-- ::,][com.atomikos.recovery.imp.CachedRepository]Corrupted log file - restart JVM
com.atomikos.recovery.LogReadException: java.lang.ArrayIndexOutOfBoundsException:
at com.atomikos.recovery.imp.FileSystemRepository.getAllCoordinatorLogEntries(FileSystemRepository.java:)
at com.atomikos.recovery.imp.CachedRepository.init(CachedRepository.java:)
at com.atomikos.icatch.provider.imp.AssemblerImp.createCoordinatorLogEntryRepository(AssemblerImp.java:)
at com.atomikos.icatch.provider.imp.AssemblerImp.assembleTransactionService(AssemblerImp.java:)
at com.atomikos.icatch.config.Configuration.assembleSystemComponents(Configuration.java:)
at com.atomikos.icatch.config.Configuration.init(Configuration.java:)
at com.atomikos.icatch.jta.UserTransactionManager.startupTransactionService(UserTransactionManager.java:)
at com.atomikos.icatch.jta.UserTransactionManager.initializeTransactionManagerSingleton(UserTransactionManager.java:)
at com.atomikos.icatch.jta.UserTransactionManager.checkSetup(UserTransactionManager.java:)
at com.atomikos.icatch.jta.UserTransactionManager.init(UserTransactionManager.java:)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
atomikos版本升级到4.0.4解决。
后续若有发现问题,再行添加。