1

我们在 Tomcat 下有一个 Web 应用程序,集成了 Hibernate 4X、Spring 4X 和 HibernateTransactionManager 作为我们的事务管理器(目前是一个 MySQL 资源)。

作为我们配置分发的一部分,我们应该与Infinispan集成作为我们的缓存管理器,以使用 MySQL 以外的其他格式存储配置。意思是,不像Hibernate 二级缓存集成!

我设法将 Infinispan 与 Spring 集成,但现在我面临一个大问题,因为 MySql 事务和 Infinispan必须在同一个 @Transactional 上

我读到了 Spring JTA 以及如何与 Atomikos 集成(例如)作为我们的全局事务管理器,但我不确定我们是否可以将整个实体结合起来一起工作以及如何:(

我需要知道是否有使用 Atomikos Spring JTA 的选项,以便 Infinispan 将识别此 JTA 实现并将MySql 和 Infinispan 作为一个全局事务处理!(2PC)

谢谢!

4

1 回答 1

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.

于 2015-01-19T15:13:41.490 回答