AnsweredAssumed Answered

How can I Separate Flush to DB and Commit

Question asked by robedgecombe on Jul 31, 2015
I have a requirement to commit transations across multiple databases that do are not use XA.
We are currently using the Spring ChainedTransactionManager and committing in an order that reduces the likelihood and impact of failure in a single database but there are some flaws in the current approach, particularly the fact that hibernate flushes on commit and that the Spring ChainedTransactionManager assumes that any database errors have already occurred before the commit method has been invoked. We have had one situation where this has occurred.

It would be better to write our own extention to the ChainedTransactionManager that flush all hibernate databases before trying to commit anything thereby conforming to the ChainedTransactionManager's expectations.

Spring's AbstractPlatformTransactionManager (and therefore the HibernateTransactoinManager that extends it) has a prepareForCommit which would allow us to flush all relevant hibernate sessions first using this method but I cannot see how to do the same for Activiti (which uses IBATIS).

Is it possible to ensure that all operations are flushed to the database before the controlling TransactionManager is invoked or to deliberately flush as part of a pre commit invoked by the controlling transaction manager's code.