BindingException: Parameter ‘MP_OPTLOCK_VERSION_ORIGINAL‘ not found. Available parameters are [param

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘MP_OPTLOCK_VERSION_ORIGINAL’ not found. Available parameters are [param1, et]
在这里插入图片描述
遇到这个异常 只有2种情况

  1. 拦截器弄错了
  2. version没有值, 如果是new出来的对象,没有给version值, 他是不知道当前版本号是多少的,没办法让版本号+1 所以报错
  3. 我遇到的问题是…以上都没错,就是给我报这个错…后面debug运行一次后,又正常了…玄学~

在这里插入图片描述

实体类

    @Version
    private Integer version;

拦截器

package com.itheima.config;

import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MybatisPlusConfig {

    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.addInnerInterceptor(new PaginationInnerInterceptor());
        mybatisPlusInterceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor());
        return  mybatisPlusInterceptor;
    }
}

测试类

    @Test
    public void testUpdateTwo() {
        //先通过要修改的数据id将当前数据查询出来
        User user1 = userMapper.selectById(12L);     //version=2
        User user2 = userMapper.selectById(12L);    //version=2
        user1.setName("Jack aaa");
        userMapper.updateById(user1);              //version=>3
        user2.setName("Jack bbb");
        userMapper.updateById(user2);               //verion=2 更新失败
    }

执行日志

JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@50f4b83d] will not be managed by Spring
==>  Preparing: SELECT id,deleted,name,gender,age,tel,version FROM user WHERE id=? AND deleted=0
==> Parameters: 12(Long)
<==    Columns: id, deleted, name, gender, age, tel, version
<==        Row: 12, 0, Jack aaa,, 22, 12345678910, 2
<==      Total: 1


Closing non transactional SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@375084c9]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@53bb71e5] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@50f4b83d] will not be managed by Spring
==>  Preparing: SELECT id,deleted,name,gender,age,tel,version FROM user WHERE id=? AND deleted=0
==> Parameters: 12(Long)
<==    Columns: id, deleted, name, gender, age, tel, version
<==        Row: 12, 0, Jack aaa,, 22, 12345678910, 2
<==      Total: 1
Closing non transactional SqlSession 

[org.apache.ibatis.session.defaults.DefaultSqlSession@53bb71e5]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@13aed42b] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@50f4b83d] will not be managed by Spring
==>  Preparing: UPDATE user SET name=?, gender=?, age=?, tel=?, version=? WHERE id=? AND version=? AND deleted=0
==> Parameters: Jack ccc(String),(String), 22(Integer), 12345678910(String), 3(Integer), 12(Long), 2(Integer)
<==    Updates: 1
Closing non transactional SqlSession 


[org.apache.ibatis.session.defaults.DefaultSqlSession@13aed42b]
Creating a new SqlSession
SqlSession [org.apache.ibatis.session.defaults.DefaultSqlSession@1de7f898] was not registered for synchronization because synchronization is not active
JDBC Connection [com.mysql.cj.jdbc.ConnectionImpl@50f4b83d] will not be managed by Spring
==>  Preparing: UPDATE user SET name=?, gender=?, age=?, tel=?, version=? WHERE id=? AND version=? AND deleted=0
==> Parameters: Jack ddd(String),(String), 22(Integer), 12345678910(String), 3(Integer), 12(Long), 2(Integer)
<==    Updates: 0
Closing non transactional SqlSession 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值