问题
We have an web application under Tomcat, integrated with Hibernate 4X, Spring 4X and HibernateTransactionManager as our transaction manager (currently one MySQL resource).
As part of our configuration distribution, we should integrate with Infinispan as our cache manager to store configuration with other format than in the MySQL. Meaning, not as Hibernate second level cache integration!
I managed to integrate Infinispan with Spring but now I'm facing a big problem due to the fact the MySql transaction and Infinispan must be on the same @Transactional.
I read about Spring JTA and how to integrate with Atomikos (e.g.) as our Global Transaction manager but I'm not sure if we can combine the whole entities to work together and how :(
I need to know if there's an option to work with Atomikos Spring JTA so the Infinispan will recognize this JTA implementation and will handle the MySql and Infinispan as one global transaction! (2PC)
Thanks!
回答1:
At first I would suggest to configure Spring + Hibernate + JTA together. Here is a very nice tutorial. If you configured everything correctly - you should have one bean of a type TransactionManager
. In above tutorial it is configured inside this block:
@Bean(initMethod = "init", destroyMethod = "close")
public TransactionManager transactionManager() throws Throwable {
UserTransactionManager userTransactionManager = new UserTransactionManager();
userTransactionManager.setForceShutdown(false);
return userTransactionManager;
}
Now you may configure Infinispan to use this transaction manager. The easiest way to achieve this, is to implement your own TransactionManagerLookup. This should return the transaction manager, which was created above.
Finally you have to create transactional cache, like this:
<local-cache name="transactional">
<transaction mode="FULL_XA"/>
</local-cache>
After that everything should work with the same Transaction Manager and Spring should handle everything within single @Transactional
annotation.
来源:https://stackoverflow.com/questions/27700949/mysql-and-infinispan-jta-implementation