This forum is now a read-only archive. All commenting, posting, registration services have been turned off. Those needing community support and/or wanting to ask questions should refer to the Tag/Forum map, and to http://spring.io/questions for a curated list of stackoverflow tags that Pivotal engineers, and the community, monitor.

Using the database transactioning.

Nov 10th, 2004, 01:15 PM

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.

Comment

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.