Announcement Announcement Module
No announcement yet.
Using the database transactioning. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using the database transactioning.

    I am converting some of the code in use for a while to use the spring. Currently I am trying to use the transactioning support in spring to have the declarative transactioning.

    After reading the documentation I realize that if I need to use the database transaction only instead of the XA. I cannot get the connection directly from datasource. I need to use DataSourceUtils.getConnection(dataSource); instead. Which is fine for me as we have only one place to get the connection.

    It looks like we also need to close the connection using DataSourceUtils.closeConnectionIfNecessary(java.sq l.Connection con, javax.sql.DataSource ds) . This is a problem for me as code to close the connection is all over the place and datasource is not available either.

    Is there any way to use the spring transactioning WITH OUT closing the connection using the util class.


  • #2
    Try org.springframework.jdbc.datasource.TransactionAwa reDataSourceProxy.



    • #3
      Thanks for the quick response. Once I make sure that DataSource is always wrapped using TransactionAwareDataSourceProxy everything works as expected no need to use DataSourceUtils for opening or closing.

      I have another minor issue: we run the same code in weblogic application server and outside as standalone. In order to be able to use the same spring configuration for both I need to be able to flip the data source used by DataSourceTransactionManager. I was thinking setting the system property dataSourceInUse and set up the configuration file as follows. It does not seem to work as system property cannot be used for ref. I would like to keep the same configuration file for both environment as this is the only difference. Can somebody suggests what are the options in this situation.

      <bean id="fwdsDataSource" class="org.springframework.jndi.JndiObjectFactoryB ean">
      <property name="jndiName">

      <bean id="dataSourceLocal"
      <property name="driverClassName"><value>----</value></property>
      <property name="url"><value>-----</value></property>
      <property name="username"><value>----</value></property>
      <property name="password"><value>-------</value></property>

      <bean id="tsTransactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
      <property name="dataSource">
      <ref local="${dataSourceInUse}"/>


      • #4

        I was able to accomplish it by reading the configuration file in my code and manipulating it little bit before passing it on to XmlBeanFactory.

        Thanks for your help.