Question

I'm using ibatis in spring to write to mysql.

I have an intermittent bug. On each cycle of a process I write two rows to the db. The next cycle I read in the rows from the previous cycle. Sometimes (one time in 30, sometimes more frequently, sometimes less) I only get back one row from the db.

I have turned off all caching I can think of. My sqlmap-config.xml just says:

<sqlMapConfig>
<settings enhancementEnabled="false" statementCachingEnabled="false" classInfoCacheEnabled="false"/>

<sqlMap resource="ibatis/model/cognitura_core.xml"/>

Is there some asynchrony, or else caching to spring or ibatis or the mysql driver that I'm missing?

Using spring 3.0.5, mybatis 2.3.5, mysql-connector-java 5.0.5

EDIT 1:

Could it be because I'm using a pool of connections (c3p0)? Is it possible the insert is still running when I'm reading. It's weird, though, I thought everything would be occuring synchronously unless I explicitly declared asynch?

Was it helpful?

Solution

Are you calling SqlSession.commit() after the inserts? C3P0 asynchronously "closes" the connections, which may be calling commit under the covers. That could explain the behavior you are seeing.

OTHER TIPS

I'm getting similar behavior. This is what I'm doing. I have an old version of IBATIS I don't plan on upgrading. You can easily move this into a decorator.

SqlMapSession session = client.openSession();
try {
    try {
        session.startTransaction();
        // do work
        session.commitTransaction();
        // The transaction should be committed now, but it doesn't always happen.
        session.getCurrentConnection().commit(); // Commit again :/
    } finally {
        session.endTransaction();
    }
} finally {
    session.close(); // would be nice if it was 'AutoCloseable'
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top