SpringJTA事务与Websphere的JPA和jndi数据源

SpringJTA事务与Websphere的JPA和jndi数据源,spring,jta,Spring,Jta,我有多个数据源和一个配置了JPA的数据库。我正在使用WebSphere7。我希望所有这些数据源都配置为全局事务。我正在使用下面的spring配置,但是事务没有按照预期的全局事务工作。如果一个数据库出现故障,那么另一个数据库将被提交,这不应作为单个全局事务。你能帮我一下吗 我有两个datasouce,一个配置如下,id=“us\u icfs\u datasource”,另一个使用JPA <jee:jndi-lookup id="entityManagerFactory" jndi-name=

我有多个数据源和一个配置了JPA的数据库。我正在使用WebSphere7。我希望所有这些数据源都配置为全局事务。我正在使用下面的spring配置,但是事务没有按照预期的全局事务工作。如果一个数据库出现故障,那么另一个数据库将被提交,这不应作为单个全局事务。你能帮我一下吗

我有两个datasouce,一个配置如下,id=“us\u icfs\u datasource”,另一个使用JPA

<jee:jndi-lookup id="entityManagerFactory" jndi-name="persistence/persistenceUnit"/> 
    <bean id="pabpp" class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor"/>

<bean id="transactionManager" class="org.springframework.transaction.jta.JtaTransactionManager" />

<!-- Needed for @Transactional annotation -->
    <tx:annotation-driven/>

<jee:jndi-lookup id="US_ICFS_DATASORCE" 
        jndi-name="jdbc/financing_tools_docgen_txtmgr"
        cache="true"
        resource-ref="true"
        proxy-interface="javax.sql.DataSource" />

首先,参与全局事务的所有数据源必须是javax.sql.XADataSource类型

您还必须将持久化单元中的事务类型设置为JTA(而不是RESOURCE_LOCAL)


您需要通知您的JPA实现您想要执行全局事务。

在Websphere上,您应该使用此bean连接到Websphere事务管理器:

<bean id="transactionManager"
     class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>

也见此

编辑:


为了使用两阶段提交(即确保跨多个资源的一致性),您需要使用XA数据源。有关详细信息,请参阅。

我们是否可以有两个不同的事务管理器—一个名为transactionManager,另一个名为wsTransactionManager,这样我的bean中只有一个使用wsTransactionManager,其余的自动使用transactionManager为什么要使用两个不同的txn manager bean?最后,无论您使用的是
JTATransactionManager
还是
WebSphereUowTransactionManager
,都将使用Websphere txn管理器,UOW bean只允许您更好地使用Websphere功能……非常感谢将解决方案更改为WebshHereUowTransactionManager,但是,如果我改为WebSphereuOWTransactionManager,我仍然无法获得预期的回滚。一个数据库正在提交,尽管我的异常是从第二个数据库返回的。下面是我的代码为了使用两阶段提交,您需要确保两个数据源都设置为websphere中的XA数据源(另请参见我在回答中添加的链接)。如果你想添加代码,我会编辑上面的问题。是的。如果你能提供一些狙击手就好了。因为如果我使用XADatasource,那么下面的代码就不起作用了…类JFFS00AStoredProcedure扩展了StoredProcedure{public JFFS00AStoredProcedure(DataSource DataSource,String spName){super(DataSource,spName);…}这里Spring StoredProcedure类只能使用Datasource而不能使用Xadasource我该怎么做,您需要通知您的JPA实现您想要执行全局事务。?如果我在下面更改为XA Datasource,那么我基于Spring的存储过程无法工作您使用的JPA实现是什么?
> @Transactional    public TemplateMapping addTemplateMapping(User user,
> TemplateMapping templateMapping)          throws
> TemplateMappingServiceException {         .... }
<bean id="transactionManager"
     class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>