SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@xxx] was not registered for synchro
目录
- 1、报错场景
- 2、问题原因及解决办法
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
帮你管理了;
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@xxx] was not registered for synchro相关推荐
- org.apache.ibatis.session.defaults.DefaultSqlSession@4f9e6460] was not registered for synchronizatio
ibatis 提示 will not be managed by Spring 使用ibatis做查询,一切功能正确运行 ,但是更新报如下提示: Creating a new SqlSession S ...
- 事务注解错误范例org.apache.ibatis.session.defaults.DefaultSqlSession
程序压测时访问量达到一定数量时程序崩溃 报错如下: Releasing transactional SqlSession [org.apache.ibatis.session.defaults.Def ...
- 解决Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlS..(22.11.20)
解决过程: 1.初始方案 在我们没有开启事务的时候,如果使用mybatis,我们会在日志中看到如下的内容:"Closing non transactional SqlSession" ...
- Cannot convert value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to requir
报错:Cannot convert value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to req ...
- 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to requir
报错:Cannot convert value of type 'org.apache.ibatis.session.defaults.DefaultSqlSessionFactory' to req ...
- 一次java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession异常解决
一次整合框架时,出现找不到类的异常,如下图所示 java.lang.NoClassDefFoundError: org/apache/ibatis/session/SqlSession 详细报错信息如 ...
- java.lang.ClassNotFoundException: org.apache.ibatis.session.SqlSession
默默记录一个被自己蠢死的错误!!! 原本可以运行的项目突然报错了..!!然后自己很纳闷,因为什么都没有改,就排了两个jar冲突,百思不得其解..然后各种百度各种找问题,就是死活找不到..知道后来认认真 ...
- java lang NoClassDefFoundError org/apache/ibatis/session/Sq
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 1.错误 ...
- Mybatis报错:nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ not found
问题 使用Mybatis过程中报错 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'XXX' no ...
最新文章
- 揭秘人工智能面试内容:8家国际巨头机器学习面试题目整理
- 怎么选?阿里P7 or 副处级干部?
- bash shell 学习记录
- 软件工程实践2017第一次作业-051502125
- 小波图像分解与重构程序存在的问题与解决办法
- 1小时内注册公司 政务中心104个窗口同厅办公
- C/C++ | Qt 实现爬虫功能,爬取CSDN博客文章
- vant状态页组件van-empty - 使用篇
- django框架基础
- Gartner:全球晶圆代工市场排行榜?台积电保持第一、联电退居第三
- marlab中主成分得分怎么求_成考数学不可触碰的雷区和得分技巧(纯干货)
- 估值模型不适用_十年十倍!绝对估值法是如何引领巴菲特买入可口可乐的?
- 手机计算机怎么玩24点游戏,计算器上的24点游戏怎么操作
- 微信小程序关键字搜索
- 人工智能行业每日必读(02·03)
- jekins基本配置
- multi-kernels、ALLOC与USE、Zero-Copy
- 初学Bootstrap,制作响应式布局
- 考研复试—软件工程(一)
- 〖Python 数据库开发实战 - MySQL篇⑮〗- 数据表结果集的排序与去除重复(去重)