Atomikos:事务包含多个持久化时的异常
Posted
技术标签:
【中文标题】Atomikos:事务包含多个持久化时的异常【英文标题】:Atomikos: exception when transaction contains more than one persist 【发布时间】:2016-08-23 01:48:08 【问题描述】:我正在试验 Atomikos 提供的独立 JPA 和 JTA / XA 事务管理。
我的简单单元测试保留了 3 条记录,包装在 JTA UserTransaction 中。
当使用 H2 作为后备数据库时,测试工作正常。
当使用 mysql 作为后备数据库时,秒持久化抛出这个异常:
com.mysql.jdbc.jdbc2.optional.MysqlXAException: XAER_INVAL: 无效参数(或不支持的命令)
(请参阅下面的完整堆栈跟踪和日志记录)。日志文件提供了更多详细信息:
警告:XA 资源 'jdbc/mysqlDs':XID '3139322E3136382E31342E3131372E746D30303030323030303831:3139322E3136382E31342E3131372E746D32' 的恢复 -5:为 XA 操作提供了无效参数>
如果我在测试中只留下一个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$2.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$1.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$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.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$2.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$1.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$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.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 jar版本? @SyedEkramUddinEmon mysql 服务器是 5.5.31(在我的 windows 机器上本地运行),连接器-J 是 5.1.38 【参考方案1】:这可能是 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
【讨论】:
感谢这帮了大忙。它被列为与 MySQL 错误相关的 Atomikos 已知问题(您的第二个链接,但是不同的项目)。 “解决方法可以在jta.properties
中设置以下属性:com.atomikos.icatch.serial_jta_transactions=false
另外,请确保在 MySQL 数据源上设置以下属性:pinGlobalTxToPhysicalConnection="true"
MariaDB 的 java 驱动程序也支持此解决方法,因为 v.1.1.8
感谢您的意见,这肯定会帮助有类似问题的人。【参考方案2】:
pinGlobalTxToPhysicalConnection=true
解决了我的问题。虽然我没有设置com.atomikos.icatch.serial_jta_transactions=false
,因为我不确定如何在 Spring Boot 中设置它。
对于那些正在寻找如何设置pingGlobalTxToPhysicalConnection
属性的人,需要将其附加到如下所示的连接字符串中
jdbc:mariadb://localhost:3306/MYDB?pinGlobalTxToPhysicalConnection=true
【讨论】:
春季如何设置com.atomikos.icatch.serial_jta_transactions=false
:spring.jta.atomikos.properties.serial-jta-transactions=false
以上是关于Atomikos:事务包含多个持久化时的异常的主要内容,如果未能解决你的问题,请参考以下文章
奇怪的 Atomikos 异常 - init() 中的错误:日志已在使用中?