用于Websphere的带有JPA和jndi数据源的Spring JTA事务 [英] Spring JTA transaction with JPA and jndi datasource for Websphere

查看:174
本文介绍了用于Websphere的带有JPA和jndi数据源的Spring JTA事务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个数据源和一个使用JPA配置的数据库.我正在使用Websphere7.我希望将所有这些数据源都配置为全局事务.我使用的是低于春季的配置,但这些事务未按预期的全局事务运行.如果一个数据库发生故障,则另一个数据库将被提交,这不应该作为单个全局事务处理.你能帮我解决我做错的地方吗?

I am having multiple datasource and one one database configured with JPA. I am using websphere 7. I want all these datasouces to be configured as global transactions. I am using below spring configurations but the transactions are not working as expected global transaction. If one db is failing then the other db is getting commited which is not expected as single global transactions. Can you please help me where i m doing incorrect,

我有2个datasouce,一个数据配置如下,使用id ="us_icfs_datasource",另一个使用JPA

I am having 2 datasouce one as configured below with id="us_icfs_datasource" and another using 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" />

我也在web.xml中添加了以下代码

also I have added below code in web.xml

 <persistence-unit-ref>
    <persistence-unit-ref-name>persistence/persistenceUnit</persistence-unit-ref-name>
    <persistence-unit-name>persistenceUnit</persistence-unit-name>
  </persistence-unit-ref> 

  <persistence-context-ref>
    <persistence-context-ref-name>persistence/persistenceUnit</persistence-context-ref-name>
    <persistence-unit-name>persistenceUnit</persistence-unit-name>
  </persistence-context-ref>

下面是我使用交易的代码

below is my code where i m using transaction

> @Transactional    public TemplateMapping addTemplateMapping(User user,
> TemplateMapping templateMapping)          throws
> TemplateMappingServiceException {         .... }

推荐答案

在Websphere上,您应该使用此bean来挂钩Websphere事务管理器:

On Websphere you should use this bean to hook into the Websphere transaction manager:

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

另请参见文章

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

In order to use 2-phase commit (i.e. ensuring consistency across multiple resources), you will need to use XA data sources. See this article for details.

这篇关于用于Websphere的带有JPA和jndi数据源的Spring JTA事务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆