Hi all,
I'm currently working on ensuring transaction safety for database operations in an larger business software.
For reasonably resons I decided to implement the programmatic approach using the DataSourceTransactionManager from Spring.
Everything seems to work fine except for that (e.g.) my insert operations aren't using the same connection that the transaction holds. Thus I got the same behavior as if using no transaction management at all. Btw connections are managed by a connection pool.
I'll provide some pseudo code to clarify my problem:
While debugging my code step by step i can verify that the transaction is fetching a connection from the pool as well as any update operation is fetching an connection from the pool too. Thus the transaction object(respectively the connection that transaction holds) is used at no time.Code:public class DataRecordDAO extends JdbcTemplate{ ... private DataSourceTransactionManager txManager; //sets datasource for DataRecordDAO public void setDataSource(DataSource paramDataSource){ ... } public void setTransactionManager(){ txManager = new DataSourceTransactionManager(this.dataSource); } ... public boolean insert(some parameters){ this.setTransactionManager(); DefaultTransactionDefinition txDef = new DefaultTransactionDefinition(); Transactionstatus txStatus = txManager.getTransaction(txDef); try{ - some business logic preparing an update string - update(updateString); if(something is true){ - some business logic preparing an update string - update(updateString); } txManager.commit(); } catch(some Exception occured){ txManager.rollback(txStatus); } } }
Am I missing something or is there some error in resoning in my code?
Thank you for your help in advance
Enrico


Reply With Quote