mahesh001 opened a new issue, #21119:
URL: https://github.com/apache/shardingsphere/issues/21119

   I am using shardingsphere version 5.1.1 with spring ( no springboot)
   
   here is  my code block for data source :
   
   `public DataSource shardingCustomer() throws SQLException {
           Map<String, DataSource> dataSourceMap = getDatasourceMap();
           Properties properties = getProperties();
           LinkedList rules = new LinkedList<>();
           ShardingRuleConfiguration shardingRuleConfig = new 
ShardingRuleConfiguration();
           shardingRuleConfig.getTables().add(getstaffTableRuleConfiguration());
           shardingRuleConfig.setDefaultTableShardingStrategy(new 
StandardShardingStrategyConfiguration("age", 
StaffTableTableShardingAlgorithm.class.getName()));
           rules.add(shardingRuleConfig);
           return  
ShardingSphereDataSourceFactory.createDataSource("turvo_connect",dataSourceMap, 
rules,
                   properties);
       }`
       
        private static ShardingTableRuleConfiguration 
getstaffTableRuleConfiguration() {
           ShardingTableRuleConfiguration st = new  
ShardingTableRuleConfiguration("staff", "turvo_connect.staff_${0..2}");
           st.setTableShardingStrategy(new 
StandardShardingStrategyConfiguration("age", 
StaffTableTableShardingAlgorithm.class.getName()));
           return st;
       }
       
          private Properties getProperties() {
           Properties properties = new Properties();
           properties.setProperty("sql.show", "true");
           return properties;
       }
   
   
       private Map<String, DataSource> getDatasourceMap() {
           Map<String, DataSource> dataSourceMap = new HashMap<>(4);
           HikariConfig hikariConfig = new HikariConfig();
                hikariConfig.setUsername("###");
                hikariConfig.setPassword("####");
                hikariConfig.setJdbcUrl("#####");
           hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
                HikariDataSource dataSource = new 
HikariDataSource(hikariConfig);
           dataSourceMap.put("turvo_connect", dataSource);
           return dataSourceMap;
       }
       
       public abstract class StaffTableTableShardingAlgorithm implements 
StandardShardingAlgorithm<Integer> {
       @Override
       public String doSharding(Collection<String> availableTargetNames,
                                PreciseShardingValue<Integer> shardingValue) {
           if (availableTargetNames.contains("staff")) {
               return "staff";
           }
           Integer tmp = shardingValue.getValue();
           int mode =tmp%3;
           return "staff_"+mode;
       }
   }`
       When i am inserting data into the table I am getting the below exception 
: 
   
       `2022-09-21 15:08:32.546  INFO 55927 --- [nio-8080-exec-5] 
c.t.p.s.ShardingService                  : got into ShardingServiceImpl -> 
insertDemo, param is -> StaffPO(id=c0b55b9b-c9f5-4bb5-a8b6-7769e91dcf95, age=9, 
name=PwrSjVxhmg, gender=M)`
   `2022-09-21 15:08:32.771  INFO 55927 --- [nio-8080-exec-5] 
o.h.e.j.b.i.AbstractBatchImpl            : HHH000010: On release of batch it 
still contained JDBC statements
   2022-09-21 15:08:32.776 ERROR 55927 --- [nio-8080-exec-5] 
c.t.p.c.StaffController                  : Error occurred while iterating  loop 
:: Insert statement does not support sharding table routing to multiple data 
nodes.; nested exception is java.lang.IllegalStateException: Insert statement 
does not support sharding table routing to multiple data nodes.
   2022-09-21 15:08:32.776 ERROR 55927 --- [nio-8080-exec-5] 
c.t.p.c.StaffController                  : 
org.springframework.dao.InvalidDataAccessApiUsageException: Insert statement 
does not support sharding table routing to multiple data nodes.; nested 
exception is java.lang.IllegalStateException: Insert statement does not support 
sharding table routing to multiple data nodes.
   java.lang.IllegalStateException: Insert statement does not support sharding 
table routing to multiple data nodes.
        at 
com.google.common.base.Preconditions.checkState(Preconditions.java:508)
        at 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingInsertStatementValidator.postValidate(ShardingInsertStatementValidator.java:101)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.lambda$createRouteContext$1(ShardingSQLRouter.java:57)
        at java.util.Optional.ifPresent(Optional.java:159)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:57)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:44)
        at 
org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:73)
        at 
org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:53)
        at 
org.apache.shardingsphere.infra.context.kernel.KernelProcessor.route(KernelProcessor.java:54)
        at 
org.apache.shardingsphere.infra.context.kernel.KernelProcessor.generateExecutionContext(KernelProcessor.java:46)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.createExecutionContext(ShardingSpherePreparedStatement.java:470)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.executeUpdate(ShardingSpherePreparedStatement.java:309)
        at 
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:197)
        at 
org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:46)
        at 
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3375)
        at 
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3908)
        at 
org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:107)
        at 
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:604)
        at 
org.hibernate.engine.spi.ActionQueue.lambda$executeActions$1(ActionQueue.java:478)
        at java.util.LinkedHashMap.forEach(LinkedHashMap.java:684)
        at 
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:475)
        at 
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:344)
        at 
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:40)
        at 
org.hibernate.event.service.internal.EventListenerGroupImpl.fireEventOnEachListener(EventListenerGroupImpl.java:107)
        at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1402)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:493)
        at 
org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3285)
        at 
org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2420)
        at 
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:449)
        at 
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:183)
        at 
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$300(JdbcResourceLocalTransactionCoordinatorImpl.java:40)
        at 
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:281)
        at 
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:101)
        at 
org.springframework.orm.hibernate5.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:643)
        at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:743)
        at 
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:711)
        at 
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:654)
        at 
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:407)
        at 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
        at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at 
org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
        at 
org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698)
        at 
com.turvo.poc.service.ShardingService$$EnhancerBySpringCGLIB$$8c97b341.insertDemo(<generated>)
        at 
com.turvo.poc.ShardingDatabaseTableApplicationTests.loopTest(ShardingDatabaseTableApplicationTests.java:137)
        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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:59)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:56)
        at 
org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
        at 
org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
        at 
org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
        at 
org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
        at 
org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
        at 
org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
        at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:366)
        at 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
        at 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
        at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
        at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
        at 
org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
        at 
org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
        at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
        at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
        at 
org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
        at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
        at 
com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:69)
        at 
com.intellij.rt.junit.IdeaTestRunner$Repeater$1.execute(IdeaTestRunner.java:38)
        at 
com.intellij.rt.execution.junit.TestsRepeater.repeat(TestsRepeater.java:11)
        at 
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:35)
        at 
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)`
       
       
       Here is my table structure :
       
   `CREATE TABLE IF NOT EXISTS staff_ ( 
   id varchar(40) NOT NULL PRIMARY KEY, 
   age int(3) DEFAULT NULL, 
   name varchar(25) DEFAULT NULL, 
   gender varchar(25) DEFAULT NULL
   )ENGINE=InnoDB;`
       
    @terrymanu 
       


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: 
[email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to