Atomikos Forum |
|
UnsupportedOperationException is thrown when persist + flush + dirty entity + commit
Steps to reproduce: 1. Start a JTA transaction 2. Persist an entity that uses transactional cache concurrency strategy 3. flush the entity manager 4. Change the entity (any property, just to make it dirty) 5. Commit the transaction Original issue reported in Infinispan issue tracking: https://issues.jboss.org/browse/ISPN-7595 Comments from Infinispan maintainer: The root cause is the order in which synchronizations are invoked in Atomikos. While JBossTM (which we use for both development & testing) invokes Synchronization#beforeCompletion in the same order as they were registered (#afterCompletion is invoked in the opposite order), Atomikos holds these in a stack and #beforeCompletion is invoked in the opposite order. As Hibernate registers itself during #openSession and Infinispan during #persist, Infinispan starts committing the transaction, an then Hibernate calls flush on the dirty entity - but at this point Infinispan does not allow to modify the transaction in commit process anymore. Link to a failing test case: https://issues.jboss.org/secure/attachment/12417668/MyApp.zip
The full stack trace:
Exception in thread "main" org.springframework.transaction.UnexpectedRollbackException: JTA transaction unexpectedly rolled back (maybe due to a timeout); nested exception is javax.transaction.RollbackException: The transaction was set to rollback only at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1026) at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730) at com.myapp.services.MyService.reproduceIssue(MyService.java:35) at com.myapp.App.main(App.java:13) Caused by: javax.transaction.RollbackException: The transaction was set to rollback only at com.atomikos.icatch.jta.TransactionImp.rethrowAsJtaRollbackException(TransactionImp.java:66) at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:207) at com.atomikos.icatch.jta.TransactionManagerImp.commit(TransactionManagerImp.java:433) at com.atomikos.icatch.jta.J2eeUserTransaction.commit(J2eeUserTransaction.java:94) at org.springframework.transaction.jta.JtaTransactionManager.doCommit(JtaTransactionManager.java:1023) ... 4 more Caused by: java.lang.UnsupportedOperationException at java.util.AbstractList.add(AbstractList.java:148) at java.util.AbstractList.add(AbstractList.java:108) at org.infinispan.transaction.impl.LocalTransaction.addModification(LocalTransaction.java:64) at org.infinispan.interceptors.TxInterceptor.enlistWriteAndInvokeNext(TxInterceptor.java:380) at org.infinispan.interceptors.TxInterceptor.visitPutKeyValueCommand(TxInterceptor.java:221) at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:78) at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99) at org.infinispan.interceptors.CacheMgmtInterceptor.updateStoreStatistics(CacheMgmtInterceptor.java:191) at org.infinispan.interceptors.CacheMgmtInterceptor.visitPutKeyValueCommand(CacheMgmtInterceptor.java:177) at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:78) at org.infinispan.interceptors.base.CommandInterceptor.invokeNextInterceptor(CommandInterceptor.java:99) at org.infinispan.interceptors.InvocationContextInterceptor.handleAll(InvocationContextInterceptor.java:110) at org.infinispan.interceptors.InvocationContextInterceptor.handleDefault(InvocationContextInterceptor.java:79) at org.infinispan.commands.AbstractVisitor.visitPutKeyValueCommand(AbstractVisitor.java:43) at org.infinispan.commands.write.PutKeyValueCommand.acceptVisitor(PutKeyValueCommand.java:78) at org.infinispan.interceptors.InterceptorChain.invoke(InterceptorChain.java:335) at org.infinispan.cache.impl.CacheImpl.executeCommandAndCommitIfNeeded(CacheImpl.java:1685) at org.infinispan.cache.impl.CacheImpl.putInternal(CacheImpl.java:1134) at org.infinispan.cache.impl.CacheImpl.put(CacheImpl.java:1124) at org.infinispan.cache.impl.DecoratedCache.put(DecoratedCache.java:453) at org.hibernate.cache.infinispan.access.TxInvalidationCacheAccessDelegate.update(TxInvalidationCacheAccessDelegate.java:53) at org.hibernate.cache.infinispan.entity.ReadWriteAccess.update(ReadWriteAccess.java:29) at org.hibernate.action.internal.EntityUpdateAction.cacheUpdate(EntityUpdateAction.java:222) at org.hibernate.action.internal.EntityUpdateAction.execute(EntityUpdateAction.java:196) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:586) at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:460) at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337) at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39) at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1428) at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:484) at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3190) at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2404) at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467) at org.hibernate.resource.transaction.backend.jta.internal.JtaTransactionCoordinatorImpl.beforeCompletion(JtaTransactionCoordinatorImpl.java:320) at org.hibernate.resource.transaction.backend.jta.internal.synchronization.SynchronizationCallbackCoordinatorNonTrackingImpl.beforeCompletion(SynchronizationCallbackCoordinatorNonTrackingImpl.java:47) at org.hibernate.resource.transaction.backend.jta.internal.synchronization.RegisteredSynchronization.beforeCompletion(RegisteredSynchronization.java:37) at com.atomikos.icatch.jta.Sync2Sync.beforeCompletion(Sync2Sync.java:50) at com.atomikos.icatch.imp.TransactionStateHandler.notifyBeforeCompletion(TransactionStateHandler.java:261) at com.atomikos.icatch.imp.TransactionStateHandler.commit(TransactionStateHandler.java:236) at com.atomikos.icatch.imp.CompositeTransactionImp.doCommit(CompositeTransactionImp.java:288) at com.atomikos.icatch.imp.CompositeTransactionImp.commit(CompositeTransactionImp.java:337) at com.atomikos.icatch.jta.TransactionImp.commit(TransactionImp.java:191) ... 7 more This was found when migrating from Hibernate 4.3.x / Infinispan 7.2.x to Hibernate 5.2.8 and Infinispan 8.2.6 |