简体   繁体   English

Spring ibatis mysql间歇性异步问题

[英]spring ibatis mysql intermittent asynchronous problem

I'm using ibatis in spring to write to mysql. 我在春季使用ibatis来写入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. 有时(30分之一,有时更频繁,有时更少),我只从数据库返回一行。

I have turned off all caching I can think of. 我关闭了所有我能想到的缓存。 My sqlmap-config.xml just says: 我的sqlmap-config.xml只是说:

<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? 是否存在一些异步性,或者缓存到spring或ibatis或我缺少的mysql驱动程序?

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

EDIT 1: 编辑1:

Could it be because I'm using a pool of connections (c3p0)? 可能是因为我正在使用连接池(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? 但是,这很奇怪,我认为除非我明确声明为异步,否则一切都会同步发生?

Are you calling SqlSession.commit() after the inserts? 插入后是否要调用SqlSession.commit()? C3P0 asynchronously "closes" the connections, which may be calling commit under the covers. C3P0异步“关闭”连接,这可能是在幕后调用commit。 That could explain the behavior you are seeing. 那可以解释您所看到的行为。

I'm getting similar behavior. 我正在得到类似的行为。 This is what I'm doing. 这就是我在做什么。 I have an old version of IBATIS I don't plan on upgrading. 我有IBATIS的旧版本,不打算升级。 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'
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM