Atomikos:事务包含多个持久化时的异常

Atomikos: exception when transaction contains more than one persist

我正在试验 Atomikos 提供的独立 JPA 和 JTA/XA 事务管理。

我的简单单元测试保留了 3 条记录,包装在 JTA UserTransaction 中。

当使用 H2 作为后备数据库时,测试工作正常。

当使用 MySQL 作为后备数据库时,second persist 抛出这个异常:

com.mysql.jdbc.jdbc2.optional.MysqlXAException: XAER_INVAL: Invalid arguments (or unsupported command)

(请参阅下面的完整堆栈跟踪和日志记录)。日志文件提供了更多详细信息:

WARNING: XA resource 'jdbc/mysqlDs': resume for XID '3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32' raised -5: invalid arguments were given for the XA operation

如果我在测试中只留下一个 persist,它就会成功。当使用 H2 而不是 MySQL.

时,同样的测试也会成功

所以问题:在MySQL的情况下,异常的原因可能是什么?

这里是来自JtaJpaMySQLAtomikosTest.java的主要测试代码:

  @Test
  public void testSingleCommitMySql() throws Exception {
    EntityManagerFactory emf = Persistence.createEntityManagerFactory("javaee7.standalone.jta.pu_mysql");
    EntityManager em = emf.createEntityManager();

    UserTransaction userTransaction = (UserTransaction) new InitialContext().lookup("java:comp/UserTransaction");
    userTransaction.begin();

    em.joinTransaction();
    em.persist(new TestEntity("FOO", "A"));
    em.persist(new TestEntity("BAR", "B"));
    em.persist(new TestEntity("BAZ", "C"));

    em.flush();
    userTransaction.commit();

    TypedQuery<TestEntity> query = em.createQuery("SELECT b FROM TestEntity b WHERE name = :name", TestEntity.class)
        .setParameter("name", "FOO");

    assertEquals("A", query.getSingleResult().getValue());

    em.close();
    emf.close();
  }

如果您需要完整的测试代码,请告诉我。

这是日志记录 + 异常的相关部分:

INFO: AtomikosDataSoureBean 'jdbc/mysqlDs': getConnection ( null )...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: AtomikosDataSoureBean 'jdbc/mysqlDs': init...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling getAutoCommit...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling getMetaData...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling createStatement...
Apr 28, 2016 12:34:57 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
Apr 28, 2016 12:34:57 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000261: Table found: twophasepoc.testentity
Apr 28, 2016 12:34:57 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000037: Columns: [name, id, value]
Apr 28, 2016 12:34:57 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000108: Foreign keys: []
Apr 28, 2016 12:34:57 PM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: HHH000126: Indexes: [primary]
Apr 28, 2016 12:34:57 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling getWarnings...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling clearWarnings...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: close()...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: createCompositeTransaction ( 10000 ): created new ROOT transaction with id 192.168.14.117.tm0000200081
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: registerSynchronization ( com.atomikos.icatch.jta.Sync2Sync@4e517165 ) for transaction 192.168.14.117.tm0000200081
Hibernate: 
    insert 
    into
        TestEntity
        (name, value) 
    values
        (?, ?)
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: AtomikosDataSoureBean 'jdbc/mysqlDs': getConnection ( null )...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: AtomikosDataSoureBean 'jdbc/mysqlDs': init...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: addParticipant ( XAResourceTransaction: 3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32 ) for transaction 192.168.14.117.tm0000200081
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: XAResource.start ( 3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32 , XAResource.TMNOFLAGS ) on resource jdbc/mysqlDs represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@16ecee1
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: registerSynchronization ( com.atomikos.jdbc.AtomikosConnectionProxy$JdbcRequeueSynchronization@35a707b3 ) for transaction 192.168.14.117.tm0000200081
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling prepareStatement(insert into TestEntity (name, value) values (?, ?),1)...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: isClosed()...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling getWarnings...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: calling clearWarnings...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: atomikos connection proxy for com.mysql.jdbc.jdbc2.optional.JDBC4ConnectionWrapper@1bb266b3: close()...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: XAResource.end ( 3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32 , XAResource.TMSUCCESS ) on resource jdbc/mysqlDs represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@16ecee1
Hibernate: 
    insert 
    into
        TestEntity
        (name, value) 
    values
        (?, ?)
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: AtomikosDataSoureBean 'jdbc/mysqlDs': getConnection ( null )...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: AtomikosDataSoureBean 'jdbc/mysqlDs': init...
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: addParticipant ( XAResourceTransaction: 3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32 ) for transaction 192.168.14.117.tm0000200081
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: XAResource.start ( 3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32 , XAResource.TMJOIN ) on resource jdbc/mysqlDs represented by XAResource instance com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection@16ecee1
Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logWarning
WARNING: XA resource 'jdbc/mysqlDs': resume for XID '3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32' raised -5: invalid arguments were given for the XA operation
com.mysql.jdbc.jdbc2.optional.MysqlXAException: XAER_INVAL: Invalid arguments (or unsupported command)
    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.mapXAExceptionFromSQLException(MysqlXAConnection.java:581)
    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.dispatchCommand(MysqlXAConnection.java:566)
    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.start(MysqlXAConnection.java:507)
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:427)
    at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:59)
    at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:64)
    at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:88)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:179)
    at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:223)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:142)
    at com.sun.proxy.$Proxy12.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.doPrepare(StatementPreparerImpl.java:124)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:122)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.prepare(IdentityGenerator.java:89)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:55)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3556)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:97)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:480)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:191)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:175)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:210)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
    at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:84)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:807)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:780)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:785)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
    at JtaJpaMySQLAtomikosTest.testSingleCommitMySql(JtaJpaMySQLAtomikosTest.java:88)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:50)
    at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.sql.SQLException: XAER_INVAL: Invalid arguments (or unsupported command)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:957)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3878)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3814)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2478)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2625)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2547)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2505)
    at com.mysql.jdbc.StatementImpl.executeInternal(StatementImpl.java:840)
    at com.mysql.jdbc.StatementImpl.execute(StatementImpl.java:740)
    at com.mysql.jdbc.jdbc2.optional.MysqlXAConnection.dispatchCommand(MysqlXAConnection.java:560)
    ... 60 more

Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logWarning
WARNING: Error enlisting in transaction - connection might be broken? Please check the logs for more information...
com.atomikos.datasource.ResourceException: XA resource 'jdbc/mysqlDs': resume for XID '3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32' raised -5: invalid arguments were given for the XA operation
    at com.atomikos.datasource.xa.XAResourceTransaction.resume(XAResourceTransaction.java:434)
    at com.atomikos.datasource.xa.session.BranchEnlistedStateHandler.<init>(BranchEnlistedStateHandler.java:59)
    at com.atomikos.datasource.xa.session.NotInBranchStateHandler.checkEnlistBeforeUse(NotInBranchStateHandler.java:64)
    at com.atomikos.datasource.xa.session.TransactionContext.checkEnlistBeforeUse(TransactionContext.java:88)
    at com.atomikos.datasource.xa.session.SessionHandleState.notifyBeforeUse(SessionHandleState.java:179)
    at com.atomikos.jdbc.AtomikosConnectionProxy.enlist(AtomikosConnectionProxy.java:223)
    at com.atomikos.jdbc.AtomikosConnectionProxy.invoke(AtomikosConnectionProxy.java:142)
    at com.sun.proxy.$Proxy12.prepareStatement(Unknown Source)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.doPrepare(StatementPreparerImpl.java:124)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:186)
    at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareStatement(StatementPreparerImpl.java:122)
    at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.prepare(IdentityGenerator.java:89)
    at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:55)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3556)
    at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:97)
    at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:480)
    at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:191)
    at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:175)
    at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:210)
    at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:288)
    at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
    at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
    at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:84)
    at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
    at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
    at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:807)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:780)
    at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:785)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
    at JtaJpaMySQLAtomikosTest.testSingleCommitMySql(JtaJpaMySQLAtomikosTest.java:88)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.junit.runners.model.FrameworkMethod.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access[=11=]0(ParentRunner.java:50)
    at org.junit.runners.ParentRunner.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

Apr 28, 2016 12:34:57 PM com.atomikos.logging.JULLogger logInfo
INFO: setRollbackOnly() called for transaction 192.168.14.117.tm0000200081

这是persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">
    <persistence-unit name="javaee7.standalone.jta.pu_mysql" transaction-type="JTA">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <jta-data-source>jdbc/mysqlDs</jta-data-source>
        <class>TestEntity</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.transaction.jta.platform" value="AtomikosJtaPlatform"/>
        </properties>
    </persistence-unit>
</persistence>

这可能是因为 MySQL XA 支持的服务器限制,https://dev.mysql.com/doc/refman/5.5/en/xa-statements.html

也可能是针对atomikos的已知问题https://www.atomikos.com/Documentation/KnownProblems#ActiveMQ_error:_34Transaction_39XID:..._39_has_not_been_started_34

这可能是一个解决方案https://www.atomikos.com/Documentation/NonXaDataSource

请参阅下面的 geert3 评论以获得更具体的解决方案。

可以浏览以下链接

https://community.oracle.com/thread/2326795 http://fogbugz.atomikos.com/default.asp?community.6.3215.2

pinGlobalTxToPhysicalConnection=true 解决了我的问题。虽然我没有设置 com.atomikos.icatch.serial_jta_transactions=false 因为我不确定如何在 Spring Boot.

中设置它

对于那些正在寻找如何设置 pingGlobalTxToPhysicalConnection 属性 的人,需要将其附加到连接字符串,如下所示

jdbc:mariadb://localhost:3306/MYDB?pinGlobalTxToPhysicalConnection=true