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.
-Jonathan
public class HenDAOIbatis extends SqlMapClientDaoSupport{
public void save(Hen hen) throws SQLException {
SqlMapClientTemplate sqlTemplate = getSqlMapClientTemplate();
SqlMapClient client = sqlTemplate.getSqlMapClient();
try {
client.startTransaction();
client.getCurrentConnection().setAutoCommit(false);
sqlTemplate.update("updateHen", hen);
sqlTemplate.delete("deleteAllChicks", hen);
for (Chick chick : hen.getChicks()) {
chick.setHenID(hen.getId());
sqlTemplate.insert("addChick", chick);
}
client.commitTransaction();
}
finally {
client.endTransaction();
}
}
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.