spring ibatis mysql 间歇性异步问题

发布于 2024-10-07 11:30:23 字数 609 浏览 5 评论 0原文

我在 Spring 中使用 ibatis 写入 mysql。

我有一个间歇性错误。在进程的每个周期中,我向数据库写入两行。下一个周期我读取上一个周期的行。有时(三十次中有一次,有时更频繁,有时更少)我只从数据库返回一行。

我已经关闭了所有我能想到的缓存。我的 sqlmap-config.xml 只是说:

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

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

是否有一些异步,或者缓存到 spring 或 ibatis 或我缺少的 mysql 驱动程序?

使用 spring 3.0.5、mybatis 2.3.5、mysql-connector-java 5.0.5

编辑1:

可能是因为我正在使用连接池(c3p0)?当我阅读时,插入是否可能仍在运行。不过,很奇怪,我认为除非我明确声明异步,否则一切都会同步发生?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

独行侠 2024-10-14 11:30:23

您在插入后调用 SqlSession.commit() 吗? C3P0 异步“关闭”连接,这可能会在幕后调用 commit。这可以解释您所看到的行为。

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.

坦然微笑 2024-10-14 11:30:23

我也有类似的行为。这就是我正在做的事情。我有一个旧版本的 IBATIS,我不打算升级。您可以轻松地将其移至装饰器中。

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'
}

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'
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文