Ibatis startBatch() only works with SqlMapClient's own start and commit transactions, not with Sprin

Posted by Brian on Stack Overflow See other posts from Stack Overflow or by Brian
Published on 2010-05-27T14:09:54Z Indexed on 2010/05/31 15:43 UTC
Read the original article Hit count: 428

Filed under:
|
|
|

Hi,

I'm finding that even though I have code wrapped by Spring transactions, and it commits/rolls back when I would expect, in order to make use of JDBC batching when using Ibatis and Spring I need to use explicit SqlMapClient transaction methods.

I.e. this does batching as I'd expect:

dao.getSqlMapClient().startTransaction();
dao.getSqlMapClient().startBatch();

int i = 0;
for (MyObject obj : allObjects)
{
    dao.storeChange(obj);

    i++;
    if (i % DB_BATCH_SIZE == 0)
    {
        dao.getSqlMapClient().executeBatch();
        dao.getSqlMapClient().startBatch();
    }
}

dao.getSqlMapClient().executeBatch();
dao.getSqlMapClient().commitTransaction();

but if I don't have the opening and closing transaction statements, and rely on Spring to manage things (which is what I want to do!), batching just doesn't happen.

Given that Spring does otherwise seem to be handling its side of the bargain regarding transaction management, can anyone advise on any known issues here?

(Database is MySQL; I'm aware of the issues regarding its JDBC pseudo-batch approach with INSERT statement rewriting, that's definitely not an issue here)

© Stack Overflow or respective owner

Related posts about java

Related posts about mysql