springboot + mybatisplus出现was not registered for synchronization because synchronization is not active
原因一:缺少事务注解,底层mybatisplus的接口方法有事务
原因二:该服务器被限制访问要连接的数据库
原因三:乐观锁失效
乐观锁由@version注解标注,有以下使用要求
支持的数据类型只有:int、Integer、long、LonDate、Timestamp、LocalDateTime
整数类型下 newVersion = oldVersion + 1
newVersion 会回写到 entity 中
仅支持 updateById(id) 与 update(entity, wrapper) 方法
在 update(entity, wrapper) 方法下, wrapper 不能复用
拓展研究:
问题一、为什么每次都Creating a new SqlSession,会不会影响性能?
Creating a new SqlSession mybatis官方就是这么和spring整合的,SqlSession是对Connection的封装,Connection都在池里呢,没什么影响。
那个是信息,就是在一个数据库连接上,启动事务,创建一个对象来管理事务,就是在数据库连接上发出transaction.start,对象来记录相关信息。对性能影响很少
问题二、明明配置了事务,确提示事务没有交给spring管理,求解?
只有连接不是spring管理的(应该是应用服务器上建立的),实际上事务还是spring管理,报错还是会回滚。
乐观锁实现方式:
版本号
- 取出记录时,获取当前version
- 更新时,带上这个version
- 执行更新时, set version = newVersion where version = oldVersion
- 如果version不对,就更新失败
时间版本
- 实现MetaObjectHandler拦截器,对要判断的时间字段进行拦截,
- 时间字段加上对应注解 @TableField(value = "UPDATE_TIME",fill = FieldFill.UPDATE)
- 取出记录时,获取当前time
- 更新时,带上这个time
- 执行更新时, set time = newTime where version = oldTime
- 如果 time 不对,就更新失败
springboot + mybatisplus出现was not registered for synchronization because synchronization is not active的更多相关文章
- spring-boot+mybatisPlus+shiro的集成demo 我用了5天
spring-boot + mybatis-plus + shiro 的集成demo我用了五天 关于shiro框架,我还是从飞机哪里听来的,就连小贱都知道,可我母鸡啊.简单百度了下,结论很好上手,比s ...
- IDEA上创建 Maven SpringBoot+mybatisplus+thymeleaf 项目
概述 在WEB领域,Java也是在不断的探索和改进,从开始的JSP--->Struts1--->Struts2+Spring--->Spring MVC--->SpringBo ...
- was not registered for synchronization because synchronization is not active
报SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7862f70e] was not registered for s ...
- springboot+mybatisplus 测试代码生成
测试springboot + mybatisplus 实现代码生成 使用默认的模板引擎 pom.xml文件 <?xml version="1.0" encoding=&q ...
- SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1fa5519] was not registered for synchronization because synchronization is not active
Creating a new SqlSessionSqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1fa5519] w ...
- 2、SpringBoot+MybatisPlus整合-------BaseCRUD
开发工具:STS 代码下载链接:GitHub管理代码 版本: Springboot:1.5.14.RELEASE 使用2.0以上的Springboot,会报出一些异常.欢迎知道异常原因的大牛解惑. M ...
- SpringBoot+MyBatisPlus整合时提示:Invalid bound statement(not found):**.dao.UserDao.queryById
场景 在使用SpringBoot+MyBatisPlus搭建后台启动项目时,使用EasyCode自动生成代码. 在访问后台接口时提示: Invilid bound statement (not fou ...
- springboot+mybatisplus+sharding-jdbc分库分表实例
项目实践 现在Java项目使用mybatis多一些,所以我也做了一个springboot+mybatisplus+sharding-jdbc分库分表项目例子分享给大家. 要是用的springboot+ ...
- springboot + mybatisPlus 入门实例 入门demo
springboot + mybatisPlus 入门实例 入门demo 使用mybatisPlus的优势 集成mybatisplus后,简单的CRUD就不用写了,如果没有特别的sql,就可以不用ma ...
- 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享四:部署到阿里云
框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 阿里云开放必要端口,mysql与t ...
随机推荐
- banner的使用
Android中banner的使用步骤 Step 1.依赖banner Gradle dependencies{ compile 'com.youth.banner:banner:1.4.9' //最 ...
- react backend and frontend download file
import { View as ViewFile} from '@/api/SafetyRule'; const Handler_DownLoadFile = (Id:number,IsEngli ...
- Two-Stream Consensus Network for Weakly-Supervised Temporal Action Localization概述
1.针对的问题 在没有帧级注释的情况下,W-TAL方法很难识别假阳性的动作建议,并生成具有精确时间边界的动作建议.具体来说,之前的W-TAL方法所面临的最关键的问题之一是缺乏排除假阳性动作建议的能力. ...
- [IDEA]的常见优化
[IDEA]的常见优化 设置方法分割线和颜色 效果图 步骤 开启方法分割线 打开File -> Setting ->Editor ->General -> Appearance ...
- BurpSuite暴力破解和防御实战
burpsuite暴力破解 工具准备 burp suite 用于攻击web 应用程序的集成平台 jsEncrypter 一个用于前端加密Fuzz的Burp Suite插件,支持base64.sha.m ...
- virtualenv管理py环境linux版
因为服务器上已经安装了python3,所以直接安装virtualenv即可 pip3 install virtualenv -i https://mirrors.aliyun.com/pypi/sim ...
- mac_office2019
mac_office2019下载 1,链接地址: mac_office2019: https://590m.com/d/28636472-44062040-dc385f (访问密码:7410) 2, ...
- Jenkins+Appium+Pytest+Allure集成
前提: 已经部署好了Jenkins环境,包括工具配置等 我的环境: Jenkins服务由安装在虚拟机上的Docker启动 Appium相关运行环境安装在虚拟机所在的主机上windows 方式:在Jen ...
- java生成uniappKey
1.首先检查下自己的电脑有无java环境,打开CMD 输入java -version,如果有安装会跟下图一样: 2.在cmd命令行中执行keytool -genkey -alias mhhk -key ...
- 拉取docker容器后启动容器的脚本
我暂且不论如何拉取docker镜像.我使用sudo docker images查看拉取的镜像. 譬如我拉取nvidia的pytorch镜像后,想要创建一个实例或启动某实例,可使用如下脚本(如果本地没有 ...