About cache after mybatis integration and spring

About cache after mybatis integration and spring

When using mybatis alone, a cache is active, the same query sql 2 times in a session, only the printed once sql statement. But when mybatis the spring with the use of a cache mybatis will fail, it will print twice sql.

That is, when mybatis into the spring, the cache mybatis will fail.

The reason is:

mybatis and spring, when used in conjunction with the original DefaultSqlSession replaced with SqlSessionTemplate, and SqlSessionTemplate sqlSession replaced with the proxy object, when we execute sqlSession.selectList method calls to SqlSessionInterceptor invoke method, fianlly the invoke method calling the SqlSessionUtils.closeSqlSession (sqlSession, SqlSessionTemplate.this.sqlSessionFactory) our session closed. Native mybatis no reason why the closed session to session because it is exposed to us, and when combined with the use of spring and does not provide a method for exposure session, it can only be shut in here, but once the session is closed, that cache naturally ineffective.
----------------
Original link: https: //blog.csdn.net/qiuz1024/article/details/100534709

Guess you like

Origin www.cnblogs.com/liuqijia/p/11588036.html