当前使用版本(必填,否则不予处理)

版本3.2.0

该问题是如何引起的?(确定最新版也有问题再提!!!)

自己开发了基于SqlHelper.sqlSession通用的更新方法,上线以后执行操作以后,就出现了连接池无法的问题

代码如下:

public static <T> boolean beachUpdateByWrapper(Collection<T> entityList, Class entity){
        Assert.notEmpty(entityList, "error: entityList must not be empty");
        String sqlStatement = SqlHelper.table(entity).getSqlStatement(SqlMethod.UPDATE.getMethod());
        List<WrapperFieldEntity> fieldList = getWrapperField(entity);
        try (SqlSession batchSqlSession = SqlHelper.sqlSessionBatch(entity)){
            int i = 0;
            for (T anEntity : entityList) {
                // 组装更新的条件
                StringBuffer sb = new StringBuffer();
                fieldList.forEach(field -> {
                    if(sb.length() == 0){
                        sb.append(String.format(whereSql, field.getWrapperField(), field.getComputeSign(), JSONObject.parseObject(JSON.toJSONString(anEntity)).get(field.getHumpColumn())));
                    }else{
                        sb.append(String.format(whereSqlAnd, field.getWrapperField(), field.getComputeSign(), JSONObject.parseObject(JSON.toJSONString(anEntity)).get(field.getHumpColumn())));
                    }
                });
                MapperMethod.ParamMap param = new MapperMethod.ParamMap();
                param.put(Constants.ENTITY, anEntity);
                param.put(Constants.WRAPPER, Wrappers.lambdaUpdate().apply(sb.toString()));
                batchSqlSession.update(sqlStatement, param);
                if (i >= 1 && i % batchSize == 0) {
                    batchSqlSession.flushStatements();
                }
                i++;
            }
            batchSqlSession.flushStatements();
        }catch (Exception e){
            log.info("beachUpdateByWrapper error", e);
        }
        return true;
    }
/**
     * 批量插入
     * @param entityList 更新数据俩表
     * @param entity 更新表的实体类型
     * @param <T>
     * @return
     */
    public static <T> boolean saveBatch(List<T> entityList, Class entity) {
        String sqlStatement = SqlHelper.table(entity).getSqlStatement(SqlMethod.INSERT_ONE.getMethod());
        try (SqlSession batchSqlSession = SqlHelper.sqlSessionBatch(entity)) {
            int i = 0;
            for (T anEntityList : entityList) {
                batchSqlSession.insert(sqlStatement, anEntityList);
                if (i >= 1 && i % batchSize == 0) {
                    batchSqlSession.flushStatements();
                }
                i++;
            }
            batchSqlSession.flushStatements();
        }catch (Exception e){
            log.info("BaseService saveBatch error ", e);
        }
        return true;
    }

    /**
     * 单个插入
     * @param entity 更新数据俩表
     * @param clas 更新表的实体类型
     * @param <T>
     * @return
     */
    public static <T> boolean saveOne(T entity, Class clas) {
        String sqlStatement = SqlHelper.table(clas).getSqlStatement(SqlMethod.INSERT_ONE.getMethod());
        try (SqlSession sqlSession = SqlHelper.sqlSession(clas)){
            sqlSession.insert(sqlStatement, entity);
            sqlSession.flushStatements();
        }catch (Exception e){
            log.info("BaseService saveOne error ",e);
            throw e;
        }
        return true;
    }

// 实体保存 BaseService.saveBatch(billDraftList, BillDraft.class);

解决办法: 添加了事务,去掉static MyBatis-Plus 使用SqlHelper.sqlSession 执行更新造成连接池无法释放

不知道这什么原因

重现步骤(如果有就写完整)

报错信息

MyBatis-Plus 使用SqlHelper.sqlSession 执行更新造成连接池无法释放 MyBatis-Plus 使用SqlHelper.sqlSession 执行更新造成连接池无法释放

Comment From: miracle-bean

https://github.com/miracle-bean/mybatis-plus/blob/bug_5608/mybatis-plus/src/test/java/com/baomidou/mybatisplus/test/mysql/SqlHelperTest.java 我在这里复现了你的代码,但是并没有遇到报错

Comment From: lifx2015

感谢,我再排查一下

Comment From: lifx2015

可能别的原因造成的