Home  >  Q&A  >  body text

java - mybatis 插入一条数据时,数据库没能找到这条数据,但是程序却可以查询出这条数据

用mybatis向mysql数据库插入一条数据后,然后查询出来。数据库里没有这条数据,但是程序通过查询语句却能查到这条数据

程序显示结果:

但是数据库就没能找到这条数据

PHP中文网PHP中文网2741 days ago445

reply all(6)I'll reply

  • 大家讲道理

    大家讲道理2017-04-18 09:54:06

    It’s not a cache at all, neither a database nor mybatis.

    The database is easy to understand. The data you have not committed can only be found in your current transaction, and cannot be found by other clients. If it is found, wouldn't it be dirty reading?

    The cache of mybatis is very simple. By default, insert, delete, and update will clear the cache. Only when selecting, will things be placed in the cache.

    So the answer is obvious, it’s the problem of turning off auto commit and not committing the update operation to the database, so you can only check it on your own, but you can’t find it if you open a client

    reply
    0
  • 高洛峰

    高洛峰2017-04-18 09:54:06

    Your picture:

    Could it be the reason for your affairs? Because you query it immediately after inserting it, but the transaction has not been submitted yet?

    reply
    0
  • 迷茫

    迷茫2017-04-18 09:54:06

    The program may use a caching mechanism. The data you inserted may be in the cache and not yet in the database. Search the database cache on Baidu

    reply
    0
  • 黄舟

    黄舟2017-04-18 09:54:06

    I think it’s because there’s no commit in

    reply
    0
  • 阿神

    阿神2017-04-18 09:54:06

    It can only mean that the transaction was not submitted

    reply
    0
  • ringa_lee

    ringa_lee2017-04-18 09:54:06

    Proper business issues. Brother, you can see it after the transaction is submitted.

    reply
    0
  • Cancelreply