当前位置:网站首页>SqlSession [[email protected]]
SqlSession [[email protected]]
2022-08-03 02:24:00 【市井榴芒】
1、报错场景
在搞SpringBoot项目的时候,把Mybatis打印日志的配置打开后,发现每条Sql打印的时候都会在前面打印如下的信息,强迫症受不了,得查查为什么;
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@521978e4] was not registered for synchronization because synchronization is not active
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@5bb2b956] will not be managed by Spring
==> Preparing: select * from xxx where xxx = ? and xxx = ?
==> Parameters: opHQA5gq2qfn1DRl069YOLv1Wv0Q(String), 0(Integer)
<== Columns: xxx, xxx, xxx, xxx
<== Row: xxx, xxx, xxx, xxx
<== Total: 1
Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@521978e4]
前面打印的内容意思大概是:这次的SqlSession未注册进来,同步关着呢哎,所以你这玩意Spring不会管理的;
2、问题原因及解决办法
原因就是你现在这个事务吧,不是Spring管理着呢,是你的数据库插件Mybatis或者MybatisPlus给你管理呢,所以Spring给你温馨提醒了一下而已,又没有报错!但是,有一种情况,比如你的方法里面逻辑比较多,增删改查的SQL比较多的话,而你自己又不清楚事务怎么管理的话,推荐你把@Transactional
给加到方法上面,让Spring接管起来当前的事务,将来报错更好回滚。
当你把@Transactional
加到方法上面时;
@Override
@Transactional
public Boolean xxxx(String xxx, String xxx) {
Txxx txxx = txxxMapper.xxx(xxx, Integer.parseInt(xxx));
//...
return true;
}
再次打印日志的话就变成了这样:
Creating a new SqlSession
Registering transaction synchronization for SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ba27661]
JDBC Connection [com.alibaba.druid.proxy.jdbc.ConnectionProxyImpl@57d27e73] will be managed by Spring
==> Preparing: select * from xxx where xxx = ? and xxx = ?
==> Parameters: opHQA5gq2qfn1DRl069YOLv1Wv1Q(String), 0(Integer)
<== Columns: xxx, xxx, xxx, xxx
<== Row: xxx, xxx, xxx, xxx
<== Total: 1
Releasing transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ba27661]
Transaction synchronization committing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ba27661]
Transaction synchronization deregistering SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ba27661]
Transaction synchronization closing SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@3ba27661]
能看见Spring已经will be managed by Spring
帮你管理了;
边栏推荐
猜你喜欢
随机推荐
YYGH-BUG-06
思维+启发式合并
孩子坐不住就是不专注?猿辅导揭秘专注力的三大误区
leetcode:151. 颠倒字符串中的单词
MySQL-Explain详解
LabVIEW程序框图保存为图像
如何画一张架构图(内含知识图谱)
leetcode:163 缺失的区间
常用工具链和虚拟环境-Cygwin
Usage of permute() function in pytorch
在VScode里调试ROS程序
重定向printf到USB CDC、串口2
会话技术!
VS中使用BugTrap定位程序崩溃点
梅科尔工作室-14天华为培训三
Spark SQL简介
# RACE32——高级断点的设置和应用
2022-08-01 顾宇佳 学习笔记
Mysql-如何进行慢SQL查询
vs studio 安装opencv 环境