我有多个数据源和一个配置有 JPA 的数据库。我正在使用 websphere 7。我希望将所有这些数据源配置为全局事务。我正在使用下面的 spring 配置,但事务没有按预期的全局事务工作。如果一个数据库发生故障,则另一个数据库将被提交,这预计不会作为单个全局事务。你能帮我解决我做错的地方吗?
我有 2 个数据源,其中一个使用 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>
下面是我使用事务的代码
> @Transactional public TemplateMapping addTemplateMapping(User user,
> TemplateMapping templateMapping) throws
> TemplateMappingServiceException { .... }
在 Websphere 上,您应该使用此 bean 来连接到 Websphere 事务管理器:
<bean id="transactionManager"
class="org.springframework.transaction.jta.WebSphereUowTransactionManager"/>
另请参阅此article http://www.ibm.com/developerworks/websphere/techjournal/0609_alcott/0609_alcott.html
EDIT:
为了使用两阶段提交(即确保多个资源之间的一致性),您将需要使用 XA 数据源。看本文 http://www.ibm.com/developerworks/websphere/library/techarticles/0407_woolf/0407_woolf.html了解详情。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)