MyBatis SQL cache, removing MyBatis cache

Source: Internet
Author: User

The second time used to Mybaits, or was the same problem pit for a few hours, so be sure to share this problem to everyone. Many users are said a lot of configuration, are in the Mybatis.xml configuration. However, I am not using mybatis.xml, my configuration is configured in each **mapper.xml, is nothing more than an association entity class path, and an alias.

In the MyBatis framework, before Sqlsession is closed, in a session, if the same SELECT statement is executed, MyBatis does not requery the database, but returns the query results cached in memory directly. This is unrelated to the MyBatis cache configuration, and changing the configuration file does not work, so you can call the Sqlsession.clearcache () function.

Personal understanding ClearCache cleans up the so-called first-level caches, which are actively performing cleanup after the Insert,update,delete method is executed. This cache is maintained by MyBatis itself. Therefore, it is generally not necessary to do manual processing.

Then you should be using a level two cache to cause the problem you are describing. That's the <cache/> tag you used in the **mapper.xml. With this tag, the MyBatis level two cache is turned on by default, so even if you use Session.clearcache () to clean up the first level cache (Local caches) during your query, the level two cache still exists.

So put **mapper.xml in the <cache/> label, remove can.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.