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.