原因一:缺少事务注解,底层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的更多相关文章

  1. spring-boot+mybatisPlus+shiro的集成demo 我用了5天

    spring-boot + mybatis-plus + shiro 的集成demo我用了五天 关于shiro框架,我还是从飞机哪里听来的,就连小贱都知道,可我母鸡啊.简单百度了下,结论很好上手,比s ...

  2. IDEA上创建 Maven SpringBoot+mybatisplus+thymeleaf 项目

    概述 在WEB领域,Java也是在不断的探索和改进,从开始的JSP--->Struts1--->Struts2+Spring--->Spring MVC--->SpringBo ...

  3. was not registered for synchronization because synchronization is not active

    报SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@7862f70e] was not registered for s ...

  4. springboot+mybatisplus 测试代码生成

    测试springboot + mybatisplus 实现代码生成   使用默认的模板引擎 pom.xml文件 <?xml version="1.0" encoding=&q ...

  5. 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 ...

  6. 2、SpringBoot+MybatisPlus整合-------BaseCRUD

    开发工具:STS 代码下载链接:GitHub管理代码 版本: Springboot:1.5.14.RELEASE 使用2.0以上的Springboot,会报出一些异常.欢迎知道异常原因的大牛解惑. M ...

  7. SpringBoot+MyBatisPlus整合时提示:Invalid bound statement(not found):**.dao.UserDao.queryById

    场景 在使用SpringBoot+MyBatisPlus搭建后台启动项目时,使用EasyCode自动生成代码. 在访问后台接口时提示: Invilid bound statement (not fou ...

  8. springboot+mybatisplus+sharding-jdbc分库分表实例

    项目实践 现在Java项目使用mybatis多一些,所以我也做了一个springboot+mybatisplus+sharding-jdbc分库分表项目例子分享给大家. 要是用的springboot+ ...

  9. springboot + mybatisPlus 入门实例 入门demo

    springboot + mybatisPlus 入门实例 入门demo 使用mybatisPlus的优势 集成mybatisplus后,简单的CRUD就不用写了,如果没有特别的sql,就可以不用ma ...

  10. 关于写SpringBoot+Mybatisplus+Shiro项目的经验分享四:部署到阿里云

    框架: SpringBoot+Mybatisplus+Shiro 简单介绍:关于写SpringBoot+Mybatisplus+Shiro项目的经验分享一:简单介绍 阿里云开放必要端口,mysql与t ...

随机推荐

  1. SSH反向隧道实现内网穿透

    1.客户端配置 /home/tsingyundev/zyy bind209.sh内容 ssh -fCNL *:1234:localhost:10022 localhost ssh209.sh内容 ss ...

  2. Echarts中国地图下钻

    //各省份的地图json文件 var provinces = { '上海': '/asset/get/s/data-1482909900836-H1BC_1WHg.json', '河北': '/ass ...

  3. FSCapture怎么取色

    启动软件后 点击setting->Screen color Picker 此时箭头会变为一个吸管形状, 选择要吸取的颜色,点击鼠标左键 出现如图所示 完了复制这个十六进制颜色值

  4. QListWidget调用Clear时报错:ASSERT failure in QList<T>::at: "index out of range"的解决方法

    原因:连接了信号currentRowChanged(int)和槽,当选中其中的一行时,在调用Clear函数就会报错. 解决方法:不连接currentRowChanged(int)信号和槽,改为连接it ...

  5. Java基础——数组的初始化与赋值、循环遍历,Random随机数[大于等于0,小于所给值)

    package com.zhao.demo; public class Demo05 { //数组的静态初始化 /*public static void main(String[] args) { i ...

  6. TypeScript - 安装,类型

    // 要使用typescript需要全局安装 通过tsc -v 来验证是否安装成功 npm i -g typescript// ts 文件中完全可以写js语法, 完全兼容js // ts 本身在运行时 ...

  7. element ui修改文本框高度以及图标不居中的问题

    .el-input__inner{ height:30px !important; .el-input__icon{ line-height: 24px !important; } .el-range ...

  8. ProcessLassoLauncher.exe

    html, body { font-size: 15px } body { font-family: Helvetica, "Hiragino Sans GB", 微软雅黑, &q ...

  9. 【2020NOI.AC省选模拟#2】A. 旋转

    题目链接 原题解: 把每个点的坐标视为复数,那么每次询问就是区间求平均数(先求和然后除以个数).一个点绕着原点旋转就是乘以$(\cos 60^\circ +i\sin 60^\circ)$. 一个点绕 ...

  10. sync.WaitGroup

    WaitGropu使用注意 作groutine参数时传指针 type WaitGroup struct { noCopy noCopy // 64-bit value: high 32 bits ar ...