Disable MyBatis3 cache

When searching using MyBatis, the default behavior is that if you call it with the same parameters in the same transaction, the cached instance will be returned without issuing SQL from the second time onward.

MyBatis3 Settings

MyBatis uses a local cache to resolve circular references and speed up nested queries. By default (SESSION), all query results in the same session are cached. If you set localCacheScope to STATEMENT, the local cache is applied statement by statement. In other words, multiple calls to the same SqlSession will not share data.

Disable cache

You can change the local cache to be managed on a statement-by-statement basis with the following settings: When managing by statement, MyBatis executes SQL every time to get the latest Entity.

application.properties


mybatis.config-location=classpath:/mybatis/mybatis-config.xml

mybatis-config.xml


<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
    PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
    "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<settings>
		<setting name="localCacheScope" value="STATEMENT" />
	</settings>
</configuration>

Recommended Posts

Disable MyBatis3 cache
MyBatis memorandum
MyBatis story