简体   繁体   English

来自Spring或JNDI的TransactionManager? (JBOSS + Spring 3 + Hibernate 4 + JTA)

[英]TransactionManager from Spring or JNDI? (JBOSS + Spring 3 + Hibernate 4 + JTA)

We are using Spring with Hibernate to establish transactions with JTA. 我们使用Spring with Hibernate与JTA建立事务。 The PlatformTransactionManager is the JtaTransactionManager which is wired with the TransactionManager and UserTransaction from narayana. PlatformTransactionManager是JtaTransactionManager,它与来自narayana的TransactionManager和UserTransaction连接。

@Bean
@Scope("prototype")
public TransactionManager jbossTransactionManager() {
    return jtaPropertyManager.getJTAEnvironmentBean().getTransactionManager();
}

@Bean
@Scope("prototype")
public UserTransaction jbossUserTransaction() {
    return jtaPropertyManager.getJTAEnvironmentBean().getUserTransaction();
}

@Bean
public PlatformTransactionManager transactionManager() {
    return new JtaTransactionManager(jbossUserTransaction(), jbossTransactionManager());
}

I have noted that JtaTransactionManager has the UT and TM I would want. 我注意到JtaTransactionManager有我想要的UT和TM。 On JBoss 6 EAP, I noted that my DataSource has been used as a WrapperDataSource and that this was related to a different TM. 在JBoss 6 EAP上,我注意到我的DataSource已被用作WrapperDataSource,并且这与不同的TM有关。 Specifically, it is using the TransactionManagerDelegate. 具体来说,它使用的是TransactionManagerDelegate。 This appears to be the transaction manager provided by JBoss via the JNDI names java:TransactionManager and java:jboss/TransactionManager . 这似乎是JBoss通过JNDI名称java:TransactionManagerjava:jboss/TransactionManager提供的事务管理器。 This is preventing my transactions from having transactional boundaries and I leak data on flush. 这可以防止我的事务具有事务边界,并且我在flush上泄漏数据。 If I remove my configuration and the UT and TM from the container, my transactions transact properly. 如果我从容器中删除配置和UT和TM,我的交易将正确处理。

  1. What is deciding to use this other TransactionManager? 什么决定使用这个其他TransactionManager? This appears to be the JCA from the container but I do not understand the mechanism for this decision. 这似乎是容器中的JCA,但我不明白这个决定的机制。
  2. Should I remove my UT and TM and surrender control to the container to give these components to my app and rely on the JTA platform as is or should I try to gain more control? 我应该删除我的UT和TM并将控制交给容器以将这些组件提供给我的应用程序并依赖JTA平台,还是应该尝试获得更多控制权?

the container provides the datasource with a transaction manager from the JCA. 容器为数据源提供来自JCA的事务管理器。 This TransactionManager is a different instance than the one we had wired in from Spring. 此TransactionManager是一个与我们从Spring连接的实例不同的实例。 (Our bean had been instantiated from the arjuna environment bean). (我们的bean已经从arjuna环境bean实例化了)。 Using the JtaManager from Spring to get the transaction manager, via JNDI in the default locations, from the container ensured that we have the same transaction manager in the JTA platform used by Hibernate (JBoss App Server in this case). 使用Spring中的JtaManager通过默认位置的JNDI从容器中获取事务管理器,确保我们在Hibernate使用的JTA平台中拥有相同的事务管理器(在本例中为JBoss App Server)。

Before we made this change, the application TransactionManager was in a transaction with Hibernate but the transactionManager on the datasource was not participating which caused the "leak". 在我们进行此更改之前,应用程序TransactionManager处于与Hibernate的事务中,但数据源上的transactionManager未参与,这导致了“泄漏”。

Using the same instance has everything working together. 使用相同的实例可以使一切工作在一起。 This has also been proven out on WebLogic using the same approach. 这也已在WebLogic上使用相同的方法证明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM