2012-09-25 92 views
4

我正在使用JPA配置多個數據源和一個數據庫。我正在使用websphere 7.我希望所有這些datasouces被配置爲全局事務。我在春季配置下面使用,但交易不按預期的全球交易。如果一個數據庫失敗,那麼另一個數據庫正在被提交,而不是單個全局事務。你可以幫我在那裏即時通訊做不正確,使用JPA和jndi datasource進行Websphere的Spring JTA事務

我有2 datasouce一個作爲配置下面使用id =「us_icfs_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" /> 

也是我在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> 
下面

是我的代碼,其中IM使用事務

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

回答

0

˚F首先,參與全局事務的所有數據源必須是javax.sql.XADataSource類型。

您還可以在您的持久性單元設置事務類型爲JTA(不RESOURCE_LOCAL)。

而你需要告知你想要做全局事務的JPA實現。

+0

我該如何做,並且您需要通知您的JPA實現您想要執行全局事務。如果我改變下面的XA數據源然後我的基於彈簧的存儲過程不工作

+0

您使用的是什麼JPA實現? –

4

WebSphere上,你應該使用這個bean掛鉤到WebSphere事務管理器:

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

參見本article

編輯:

爲了使用兩階段提交(即確保跨多個資源的一致性),您將需要使用XA數據源。有關詳細信息,請參見this article

+0

也可以,我們有兩個不同的事務管理器與一個名字的TransactionManager和另一名稱爲wsTransactionManager,這樣只有我的豆使用wsTransactionManager之一,自動休息需要transactionManager的 –

+0

你爲什麼要使用兩種不同的TXN經理豆?最後,無論您是使用'JTATransactionManager'還是'WebSphereUowTransactionManager',都將使用Websphere txn manager,UOW bean只是讓您更好地使用websphere的功能。¶ – beny23

+0

嘿非常感謝您的解決方案更改爲WebshphereUowTransactionManager,但如果我更改爲websphereuowtransactionmanger,我仍然沒有按預期得到回滾。一個數據庫正在提交事件,但我的異常是從第二個數據庫返回的。下面是我的代碼 –

相關問題