多数据源,采用ThreadLocal来动态切换数据源,在保存对象时候需要保证事务的统一性,采用JTA事务实现,第三方支持为Atomikos3.7。但是在保存对象的时候报错:
[code=Java]10:54:55,635 DEBUG org.hibernate.jdbc.AbstractBatcher:433 - about to close ResultSet (open ResultSets: 1, globally: 1)
10:54:55,635 DEBUG org.hibernate.jdbc.AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
10:54:55,635 DEBUG org.hibernate.engine.StatefulPersistenceContext:893 - initializing non-lazy collections
10:54:56,068 WARN atomikos:107 - JDBC ConnectionPool exhausted - allocated new connection: ExternalXAPooledConnectionImp1347245696068com.atomikos.jdbc.ExclusiveExternalXAPooledConnectionImp@d64956
10:54:56,068 DEBUG org.hibernate.SQL:111 - select idValue from id_manage where idName = 'tenantId' for update
10:54:56,068 DEBUG org.hibernate.SQL:111 - update id_manage set idValue = ? where idValue = ? and idName = 'tenantId'
10:54:56,084 DEBUG org.hibernate.util.JDBCExceptionReporter:225 - error performing isolated work [???]
java.sql.SQLException: XAER_RMFAIL: The command cannot be executed when global transaction is in the ACTIVE state
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1075)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2562)
at com.mysql.jdbc.ConnectionImpl.rollbackNoChecks(ConnectionImpl.java:4788)
at com.mysql.jdbc.ConnectionImpl.rollback(ConnectionImpl.java:4671)
at com.mysql.jdbc.ConnectionImpl.realClose(ConnectionImpl.java:4279)
at com.mysql.jdbc.ConnectionImpl.close(ConnectionImpl.java:1544)
at com.mysql.jdbc.jdbc2.optional.MysqlPooledConnection.close(MysqlPooledConnection.java:207)
at com.mysql.jdbc.jdbc2.optional.JDBC4MysqlXAConnection.close(JDBC4MysqlXAConnection.java:51)
at com.atomikos.jdbc.ExternalXAPooledConnectionImp.close(ExternalXAPooledConnectionImp.java:188)
at com.atomikos.jdbc.ConnectionProxy.invoke(ConnectionProxy.java:183)
at $Proxy17.commit(Unknown Source)
at org.hibernate.engine.transaction.Isolater$JdbcDelegate.delegateWork(Isolater.java:252)
at org.hibernate.engine.transaction.Isolater.doIsolatedWork(Isolater.java:70)
at org.hibernate.engine.TransactionHelper.doWorkInNewTransaction(TransactionHelper.java:74)
at org.hibernate.id.MultipleHiLoPerTableGenerator.generate(MultipleHiLoPerTableGenerator.java:208)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
code].......
请问如何解决?
--转自