springboot + mybatis plus + druid进行数据库交互,出现以下提示:

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@77a86d01] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@548fc58e] 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 [org.apache.ibatis.session.defaults.DefaultSqlSession@193b04b2]
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@548fc58e] will be managed by Spring

com.baomidou.mybatisplus.mapper.BaseMapper,执行insert的时候显示:

Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@77a86d01] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@548fc58e] will not be managed by Spring。

对比代码发现:ServiceImpl其实是有@Transactional注解的。说白了,出现以上问题终归到底还是事物的问题。

 

参考资料:https://bbs.csdn.net/topics/392265614

Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐