springboot + mybatis出现was not registered for synchronization because synchronization is not active
springboot + mybatis plus + druid进行数据库交互,出现以下提示:
Creating a new SqlSession
SqlSession [[email protected]] was not registered for synchronization because synchronization is not active
JDBC Connection [[email protected]] will not be managed by Spring
问题一、为什么每次都Creating a new SqlSession,会不会影响性能?
那个是信息,就是在一个数据库连接上,启动事务,创建一个对象来管理事务,就是在数据库连接上发出transaction.start,对象来记录相关信息。对性能影响很少
问题二、明明配置了事务,确提示事务没有交给spring管理,求解
是连接不是spring管理的(应该是应用服务器上建立的),事务还是spring管理。也是正常的
我在使用的时候发现com.baomidou.mybatisplus.service.impl.ServiceImpl,执行insert的时候显示:
Creating a new SqlSession
Registering transaction synchronization for SqlSession [[email protected]]
JDBC Connection [[email protected]] will be managed by Spring
com.baomidou.mybatisplus.mapper.BaseMapper,执行insert的时候显示:
Creating a new SqlSession
SqlSession [[email protected]] was not registered for synchronization because synchronization is not active
JDBC Connection [[email protected]] will not be managed by Spring。
对比代码发现:ServiceImpl其实是有@Transactional注解的。说白了,出现以上问题终归到底还是事物的问题。