shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

version 3.1.0 not support batch insert

Open maxiaoxian opened this issue 7 years ago • 7 comments

maxiaoxian avatar Mar 07 '19 08:03 maxiaoxian

Caused by: java.lang.NullPointerException at io.shardingsphere.shardingjdbc.jdbc.core.statement.ShardingPreparedStatement.execute(ShardingPreparedStatement.java:139) at sun.reflect.GeneratedMethodAccessor187.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.logging.jdbc.PreparedStatementLogger.invoke(PreparedStatementLogger.java:59) at com.sun.proxy.$Proxy133.execute(Unknown Source) at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:46) at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74) at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:63) at com.sun.proxy.$Proxy131.update(Unknown Source) at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:198)

maxiaoxian avatar Mar 07 '19 08:03 maxiaoxian

Please support configuration file, and your core JAVA source code that can show how you use PreparedStatement.addBatch() and PreparedStatement.executeBatch()

tristaZero avatar Mar 07 '19 09:03 tristaZero

@Bean(name = "shardingDataSource") @Primary public DataSource getShardingDataSource() throws SQLException { // 读写分离配置 MasterSlaveRuleConfiguration masterSlaveRuleConfig = new MasterSlaveRuleConfiguration("ds", "fcWriteDataSource", Arrays.asList("fcRead1DataSource", "fcRead2DataSource"), MasterSlaveLoadBalanceAlgorithmType.getDefaultAlgorithmType().getAlgorithm());

    Set<MasterSlaveRuleConfiguration> masterSlaveRuleConfigurationSet = new HashSet<>();
    masterSlaveRuleConfigurationSet.add(masterSlaveRuleConfig);

    ShardingRuleConfiguration shardingRuleConfig = new ShardingRuleConfiguration();
    shardingRuleConfig.setMasterSlaveRuleConfigs(masterSlaveRuleConfigurationSet);

    // 分表规则配置
    TableRuleConfiguration f_order_report = getTableRule("f_order_report", "ds.f_order_report_${['123','432']}", "ou_id");
    TableRuleConfiguration f_order_business_model = getTableRule("f_order_business_model", "ds.f_order_business_model_${['123','432']}", "ou_id");
    shardingRuleConfig.getTableRuleConfigs().add(f_order_report);
    shardingRuleConfig.getTableRuleConfigs().add(f_order_business_model);

    // 默认分表策略设置

// shardingRuleConfig.setDefaultTableShardingStrategyConfig( // new StandardShardingStrategyConfiguration("none", // new NoneDatabaseShardingAlgorithm())); shardingRuleConfig.setDefaultTableShardingStrategyConfig(new NoneShardingStrategyConfiguration()); // 设置默认数据库,解决只有部分表需要分表的问题 shardingRuleConfig.setDefaultDataSourceName("fcWriteDataSource"); Map<String, Object> configMap = new HashMap<>(); return ShardingDataSourceFactory.createDataSource(createDataSourceMap(), shardingRuleConfig, configMap, new Properties()); }

maxiaoxian avatar Mar 07 '19 09:03 maxiaoxian

insert into f_order_business_model ( ) values ( #{item.orderId,jdbcType=BIGINT} , .... )

maxiaoxian avatar Mar 07 '19 09:03 maxiaoxian

If you execute a simple INSERT VALUES() by using this configuration, is it ok? By the way, can you provide more exception log? I have no idea of how it happens. If you are free, can you try to debug it?

tristaZero avatar Mar 08 '19 10:03 tristaZero

@maxiaoxian

tristaZero avatar Mar 15 '19 02:03 tristaZero

Please pay attention on issues you submitted, because we maybe need more details. If no response more than 7 days and we cannot reproduce it on current information, we will close it.

terrymanu avatar Mar 15 '19 03:03 terrymanu