MySQL and Infinispan - JTA implementation

ぃ、小莉子 提交于 2019-12-24 15:33:00

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!