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

3.3.1 4.1.1

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

引入sharding-jdbc管理数据源前可以正常返回mysql表自增主键 引入后,单条save方法,表实体类会注入主键,但saveBatch方法无效,实体类@TableId字段为null

Comment From: ppx-build-code

既然都分表了,不建议使用自增的主键,

Comment From: 54lyll

不是分表的插入,是其他普通表的插入

Comment From: ppx-build-code

shardingjdbc重写了statement,三个建议: 1.配置多个数据源做隔离 2.用分布式id 3.再查一遍 都不是很好的

Comment From: miemieYaho

找 shardingjdbc 去

Comment From: xin-zero

很好奇 ,为啥要关闭呢,这个问题解决没有

Comment From: freshgeek

https://github.com/apache/shardingsphere/issues/9592

Comment From: freshgeek

踢皮球时间到

Comment From: freshgeek

踢皮球时间到

Comment From: Tsaishichung

踢皮球时间到

@freshgeek 应该就是shardingsphere的bug,强行修改了一波源码测试了一下可以用了。复写一些这个类ShardingSpherePreparedStatement

public void addBatch() {
        try {
            QueryContext queryContext = this.createQueryContext();
            this.trafficInstanceId = this.getInstanceIdAndSet(queryContext).orElse(null);
            this.executionContext = null != this.trafficInstanceId ? this.createExecutionContext(queryContext, this.trafficInstanceId) : this.createExecutionContext(queryContext);
            this.batchPreparedStatementExecutor.addBatchForExecutionUnits(this.executionContext.getExecutionUnits());

            // 这里加一下缓存statement,cacheBatchStatements是新方法
            ExecutionGroupContext<JDBCExecutionUnit> executionGroupContext = this.createExecutionGroupContext();
            this.cacheBatchStatements(executionGroupContext.getInputGroups());
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } finally {
            this.currentResultSet = null;
            this.clearParameters();
        }
    }

private void cacheBatchStatements(Collection<ExecutionGroup<JDBCExecutionUnit>> executionGroups) throws SQLException {
        Iterator var2 = executionGroups.iterator();

        while(var2.hasNext()) {
            ExecutionGroup<JDBCExecutionUnit> each = (ExecutionGroup<JDBCExecutionUnit>)var2.next();
            each.getInputs().forEach((eachInput) -> {
                if (!this.statements.contains((PreparedStatement)eachInput.getStorageResource())) {
                    this.statements.add((PreparedStatement)eachInput.getStorageResource());
                }
            });
        }
    }