Git Product home page Git Product logo

mp-ssf-demo's Introduction

  1. mybatis-plus从3.5.5升级至3.5.6,使用ServiceImpl的saveBatch方法报错demo,
    • 执行单元测试代码:com.magictan.service.TestServiceTest.test
    • Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.magictan.mapper.TestMapper.insert
  2. 项目中存在多个sqlSessionFactory,升级3.5.6后,TestService获取到了错误的sqlSessionFactory
  3. 比对3.5.5和3.5.6版本代码差异,发现差异来自3.5.5和3.5.6版本ServiceImpl.getSqlSessionFactory的这行代码:
// 3.5.6版本代码 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.getSqlSessionFactory
@SuppressWarnings({"rawtypes", "deprecation"})
protected SqlSessionFactory getSqlSessionFactory() {
   if (this.sqlSessionFactory == null) {
      synchronized (this) {
         if (this.sqlSessionFactory == null) {
            Object target = this.baseMapper;
            // 这个检查目前看着来说基本上可以不用判断Aop是不是存在了.
            if (com.baomidou.mybatisplus.extension.toolkit.AopUtils.isLoadSpringAop()) {
               while (AopUtils.isAopProxy(target)) {
                  target = AopProxyUtils.getSingletonTarget(target);
               }
            }
            if (target instanceof MybatisMapperProxy) { // 3.5.6 使用 instanceof 判断,最后TestService走到else分支
               MybatisMapperProxy mybatisMapperProxy = (MybatisMapperProxy) Proxy.getInvocationHandler(target);
               SqlSessionTemplate sqlSessionTemplate = (SqlSessionTemplate) mybatisMapperProxy.getSqlSession();
               this.sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
            } else {
               this.sqlSessionFactory = GlobalConfigUtils.currentSessionFactory(this.entityClass);
            }
         }
      }
   }
   return this.sqlSessionFactory;
}

// 3.5.5版本代码 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl.getSqlSessionFactory
@SuppressWarnings({"rawtypes", "deprecation"})
protected SqlSessionFactory getSqlSessionFactory() {
   if (this.sqlSessionFactory == null) {
      synchronized (this) {
         if (this.sqlSessionFactory == null) {
            Object target = this.baseMapper;
            // 这个检查目前看着来说基本上可以不用判断Aop是不是存在了.
            if (com.baomidou.mybatisplus.extension.toolkit.AopUtils.isLoadSpringAop()) {
               if (AopUtils.isAopProxy(this.baseMapper)) {
                  target = AopProxyUtils.getSingletonTarget(this.baseMapper);
               }
            }
            if (target != null) { // 3.5.5 使用 != null 判断,最后TestService走到if分支
               MybatisMapperProxy mybatisMapperProxy = (MybatisMapperProxy) Proxy.getInvocationHandler(target);
               SqlSessionTemplate sqlSessionTemplate = (SqlSessionTemplate) mybatisMapperProxy.getSqlSession();
               this.sqlSessionFactory = sqlSessionTemplate.getSqlSessionFactory();
            } else {
               this.sqlSessionFactory = GlobalConfigUtils.currentSessionFactory(this.entityClass);
            }
         }
      }
   }
   return this.sqlSessionFactory;
}

mp-ssf-demo's People

Contributors

mvp2142 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.