Using spring's [3.1] SimpleJdbcCall to call a stored procedure in a Oracle db. Again, there is another transaction using JPA 2.0 [hibernate 3.6.8]. Both of them needs to be committed in a single xa transaction. I would like to use JBoss AS's [7.1.1] transaction manager for JTA.
From my 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 />
Now, how to enlist spring jdbc transaction within JTA transaction manager's scope so that I can use declarative @Transactional annotation for data access calls from a single method?
My assumption was as I do not see any links between "datasource" [which is the datasource for Spring JDBC] and transaction manager, I have to do something extra to enforce JDBC transaction to be enlisted in JTA transaction manager. And when I was debugging I also found that spring JDBC transactions were committed as soon as it leaves simpleJDBCCallobject.execute method. And that's why I thought I was doing wrong. Actually, applicationContext configuration was fine. My jndi data sources were not XADatasources! While configuring XADatasources in JBoss AS 7.1, I had to use multiple properties to describe the url [instead of a single URL property] :
<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>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.