ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jonathan Slate <jsl...@mtl.mit.edu>
Subject Re: transactions with Spring DAOs
Date Wed, 14 Mar 2007 14:29:16 GMT
I share your pain, I'm having the same problem using postgres, I've 
verified that with straight JDBC, transactions work fine, but using 
SqlMapClient startTransaction seems to be doing autocommit. Here's a 
short example. You can see I've tried calling 
client.getCurrentConnection().setAutoCommit(false); (which seems to be 
on by default) but it does not help.

If I pass in a Hen with a list of Chicks where one chick's name is too 
long I get an SQL exception, but the Hen is still updated (i.e. the 
Hen's name is changed).

I'm going to keep playing with this... but any suggestions are welcome.


public class HenDAOIbatis extends SqlMapClientDaoSupport{

public void save(Hen hen) throws SQLException {
SqlMapClientTemplate sqlTemplate = getSqlMapClientTemplate();
SqlMapClient client = sqlTemplate.getSqlMapClient();

try {

sqlTemplate.update("updateHen", hen);
sqlTemplate.delete("deleteAllChicks", hen);

for (Chick chick : hen.getChicks()) {
sqlTemplate.insert("addChick", chick);
finally {

Mark Volkmann wrote:
> I wrote some JDBC code this morning to verify that the version of 
> MySQL I'm using and the driver I'm using is handling transactions 
> correctly and it is.
> That brings me back to Spring DAOs generated by Abator. I'm convinced 
> that simply calling the SqlMapClient startTransaction method does not 
> disable MySQL auto-commit. I must need to do something else to disable 
> that, but I don't know what.
> I'll look into using Spring declarative transactions and see if that 
> works, but I'd really like a solution using SqlMapClient 
> startTransaction.

View raw message