使用spring的[3.1] SimpleJdbcCall调用Oracle数据库中的存储过程。 同样,还有另一个使用JPA 2.0 [hibernate 3.6.8]的事务。它们都需要在单个xa事务中提交。我想将JBoss AS的[7.1.1]事务管理器用于JTA。
来自我的applicationContext.xml>
<!-- injecting jdbc datasource -->
<bean id="CbsTransactionRepository"
class="com.misl.treasury.cbsIntegration.repository.CbsTransactionRepositoryJDBC">
<property name="dataSource" ref="dataSource" />
</bean>
<jee:jndi-lookup id="dataSource" jndi-name="java:/jboss/datasources/CoreDS"/>
<jee:jndi-lookup id="treasuryDataSource" jndi-name="java:/jboss/datasources/TreasuryDS"/>
<!-- JPA entity manager -->
<bean id="treasuryEntityManager"
class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
</bean>
</property>
<property name="dataSource" ref="treasuryDataSource" />
<property name="persistenceUnitName" value="persistenceUnit" />
<property name="persistenceXmlLocation" value="classpath*:META-INF/hibernatepersistence.xml" />
</bean>
<bean
class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="txManager"
class="org.springframework.transaction.jta.JtaTransactionManager">
<property name="transactionManagerName" value="java:jboss/TransactionManager" />
<property name="userTransactionName" value="java:jboss/UserTransaction" />
</bean>
<tx:annotation-driven transaction-manager="txManager" />
<tx:jta-transaction-manager />
现在,如何在JTA事务管理器的范围内登记spring jdbc事务,以便我可以使用声明式@Transactional注释从单个方法进行数据访问调用?
答案 0 :(得分:0)
我的假设是因为我没有看到“数据源”[这是Spring JDBC的数据源]和事务管理器之间的任何链接,我必须做一些额外的事情来强制要在JTA事务管理器中登记JDBC事务。当我调试时,我还发现Spring JDBC事务一离开simpleJDBCCallobject.execute方法就会被提交。这就是为什么我认为我做错了。实际上,applicationContext配置很好。我的jndi数据源不是XADatasources!在JBoss AS 7.1中配置XADatasources时,我不得不使用多个属性来描述url [而不是单个URL属性]:
<datasources>
<xa-datasource jndi-name="java:jboss/datasources/TreasuryDS" pool-name="TreasuryDS" enabled="true" use-ccm="false">
<xa-datasource-property name="ServerName">
192.168.1.197
</xa-datasource-property>
<xa-datasource-property name="User">
treasury
</xa-datasource-property>
<xa-datasource-property name="Password">
treasury
</xa-datasource-property>
<xa-datasource-property name="PortNumber">
1521
</xa-datasource-property>
<xa-datasource-property name="DatabaseName">
XE
</xa-datasource-property>
<xa-datasource-property name="DriverType">
thin
</xa-datasource-property>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
<driver>OracleJDBCDriver</driver>
<xa-pool>
<is-same-rm-override>false</is-same-rm-override>
<interleaving>false</interleaving>
<pad-xid>false</pad-xid>
<wrap-xa-resource>false</wrap-xa-resource>
</xa-pool>
<security>
<user-name>treasury</user-name>
<password>treasury</password>
</security>
<validation>
<valid-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleValidConnectionChecker"/>
<validate-on-match>false</validate-on-match>
<background-validation>false</background-validation>
<stale-connection-checker class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleStaleConnectionChecker"/>
<exception-sorter class-name="org.jboss.jca.adapters.jdbc.extensions.oracle.OracleExceptionSorter"/>
</validation>
<statement>
<share-prepared-statements>false</share-prepared-statements>
</statement>
</xa-datasource>
<!---
...... here goes another XA Datasource .....
---->
<drivers>
<driver name="OracleJDBCDriver" module="com.oracle.jdbc">
<driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
<xa-datasource-class>oracle.jdbc.xa.client.OracleXADataSource</xa-datasource-class>
</driver>
<driver name="h2" module="com.h2database.h2">
<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
</driver>
</drivers>
</datasources>