How do i set the transaction manager for my datasource when using IBATIS + Spring? Does it need to be in code or just my applicationContext?
Thanks,
David
How do i set the transaction manager for my datasource when using IBATIS + Spring? Does it need to be in code or just my applicationContext?
Thanks,
David
You can define a org.springframework.jdbc.datasource.DataSourceTran sactionManager for your DataSource. SqlMapTemplate and SqlMapClientTemplate will automatically participate in such transactions, just like JdbcTemplate does.
Juergen
Have a look at the sample applications (for example, Petclinic or imagedb) that come with the Spring distribution, regarding how to set up transactional proxies. Essentially, you'll need a TransactionProxyFactoryBean per service, automatically executing specific methods in transactions.
Juergen
I have looked around and am still not sure what i need to do.
I have added the lines:
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSou rceTransactionManager">
<property name="dataSource"><ref local="dataSource"/></property>
</bean>
to my applicationContext.xml
Now what do i do to use it? (I do not hvae anything that requires an explicit start transaction).
Thanks,
David
Juergen, what i am asking is, if i have nothing more than inserts to do, do i still need to use the proxyfactorybean?
You shouldn't need to execute your data access operations in transactions. In general, it's recommended to proxy your service facades with a TransactionProxyFactoryBean (which is in turn wired with the transaction manager), but that's not required.
Actually, executing without transactions will just work if you activate default auto-commit in your connection pool. If default auto-commit is turned off, explicit commits are necessary, i.e. explicit transaction demarcation. Maybe you should double-check that.
Juergen
Yes, I also thought i did not need to execute with transactions. And this is true when i use JNDI or the DriverManagerDataSource. But when i use DBCP, even when i set defaultautocommit to on, the commits are not happening. I think this is related to how IBATIS usese the general transaction manager that is messing me up.
Thanks,
Davod
Juergen,
A simple solution to this would be to add a transasctionManager property to SQLMapClientfactoryBean. This would allow the user to not use Spring transaction management and allow the built in IBATIS transaction managerment to be used instead.
As a test, I changed the spring code to use the JDBCTransactionConfig instead of the ExternalTransactionConfig and it worked great.
Would this be an acceptable change to you?
I have now tried to use the transaction manger, and the following lines appear in the log file,
2004-11-28 12:54:20,953 [main] DEBUG java.sql.PreparedStatement - {pstm-100001} PreparedStatement: INSERT INTO dummy values (SYSDATE)
2004-11-28 12:54:20,953 [main] DEBUG java.sql.PreparedStatement - {pstm-100001} Parameters: []
2004-11-28 12:54:20,953 [main] DEBUG java.sql.PreparedStatement - {pstm-100001} Types: []
2004-11-28 12:54:20,968 [main] DEBUG org.springframework.transaction.interceptor.Transa ctionInterceptor - Invoking commit for transaction on method 'insertRequest' in class [spring.DummyInsert]
2004-11-28 12:54:20,968 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTran sactionManager - Triggering beforeCommit synchronization
2004-11-28 12:54:20,968 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTran sactionManager - Triggering beforeCompletion synchronization
2004-11-28 12:54:20,984 [main] DEBUG org.springframework.jdbc.datasource.DataSourceTran sactionManager - Triggering afterCompletion synchronization
2004-11-28 12:54:20,984 [main] DEBUG org.springframework.transaction.support.Transactio nSynchronizationManager - Clearing transaction synchronization
These would make me think that it works, yet i do not see the commit succeeding.
Any ideas?
Thanks,
David