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

   ## Question
   I use distributed sequence generation in my project, and always get the 
error Column 'order_id' cannot be null
   
   
   ##Version
   SpringBoot 2.1.0
   ShardingSphere-jdbc 5.0.0
   mybatis-spring-boot-starter  2.2.2
   druid 1.2.9
   
   ##SQL
   
![图片](https://user-images.githubusercontent.com/72535046/163155979-d32499dd-043a-41f2-bb05-0bd06133ae1f.png)
   
   
   ##application-sharding-tables.properties file
   spring.shardingsphere.mode.type=Standalone
   spring.shardingsphere.mode.repository.type=File
   spring.shardingsphere.mode.overwrite=true
   
   spring.shardingsphere.datasource.names=ds-0
   
   
spring.shardingsphere.datasource.ds-0.type=com.alibaba.druid.pool.DruidDataSource
   
spring.shardingsphere.datasource.ds-0.driver-class-name=com.mysql.cj.jdbc.Driver
   
spring.shardingsphere.datasource.ds-0.url=jdbc:mysql://localhost:3306/db_shardingsphere_test_1?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false
   spring.shardingsphere.datasource.ds-0.username=root
   spring.shardingsphere.datasource.ds-0.password=123
   
   
spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds-0.t_order_0
   
   spring.shardingsphere.sharding.tables.t_order.key-generator.column=order_id
   spring.shardingsphere.sharding.tables.t_order.key-generator.type=snowflake
   
spring.shardingsphere.sharding.tables.t_order.key-generator.props.worker.id=123
   
   spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
   
   spring.shardingsphere.props.sql-show=true
   
   ##run log
   2022-04-13 18:02:29.235  INFO 22084 --- [           main] ShardingSphere-SQL 
                      : Logic SQL: INSERT INTO t_order_0(order_id,user_id, 
total_price, state, create_time, update_time, group_bit)
           VALUES (?,?, ?, ?, ?, ?, ?)
   2022-04-13 18:02:29.235  INFO 22084 --- [           main] ShardingSphere-SQL 
                      : SQLStatement: 
MySQLInsertStatement(setAssignment=Optional.empty, 
onDuplicateKeyColumns=Optional.empty)
   2022-04-13 18:02:29.235  INFO 22084 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds-0 ::: INSERT INTO 
t_order_0(order_id,user_id, total_price, state, create_time, update_time, 
group_bit)
           VALUES (?, ?, ?, ?, ?, ?, ?) ::: [null, 1, 5, 0, 2022-04-13 
18:02:28.48, 2022-04-13 18:02:28.48, 1]
   
   org.springframework.dao.DataIntegrityViolationException: 
   ### Error updating database.  Cause: 
java.sql.SQLIntegrityConstraintViolationException: Column 'order_id' cannot be 
null
   ### The error may exist in com/liwen/pay/dao/OrderDao.java (best guess)
   ### The error may involve com.liwen.pay.dao.OrderDao.insert-Inline
   ### The error occurred while setting parameters
   ### SQL: INSERT INTO t_order_0(order_id,user_id, total_price, state, 
create_time, update_time, group_bit)         VALUES (?,?, ?, ?, ?, ?, ?)
   ### Cause: java.sql.SQLIntegrityConstraintViolationException: Column 
'order_id' cannot be null
   ; Column 'order_id' cannot be null; nested exception is 
java.sql.SQLIntegrityConstraintViolationException: Column 'order_id' cannot be 
null
   
        at 
org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:87)
        at 
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72)
        at 
org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
        at 
org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:91)
        at 
org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:441)
        at com.sun.proxy.$Proxy214.insert(Unknown Source)
        at 
org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:272)
        at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:62)
        at 
org.apache.ibatis.binding.MapperProxy$PlainMethodInvoker.invoke(MapperProxy.java:145)
        at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:86)
        at com.sun.proxy.$Proxy217.insert(Unknown Source)
        at OrderMapperTest.testInsert(OrderMapperTest.java:36)
        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:50)
        at 
org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
        at 
org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
        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:325)
        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$3.run(ParentRunner.java:290)
        at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
        at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
        at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
        at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
        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.run(ParentRunner.java:363)
        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.startRunnerWithArgs(IdeaTestRunner.java:33)
        at 
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
   Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 
'order_id' cannot be null
        at 
com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:117)
        at 
com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122)
        at 
com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953)
        at 
com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:371)
        at 
com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:497)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement$2.executeSQL(ShardingSpherePreparedStatement.java:322)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement$2.executeSQL(ShardingSpherePreparedStatement.java:318)
        at 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback.execute(JDBCExecutorCallback.java:85)
        at 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback.execute(JDBCExecutorCallback.java:64)
        at 
org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine.syncExecute(ExecutorEngine.java:101)
        at 
org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine.parallelExecute(ExecutorEngine.java:97)
        at 
org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine.execute(ExecutorEngine.java:82)
        at 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor.execute(JDBCExecutor.java:65)
        at 
org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor.execute(JDBCExecutor.java:49)
        at 
org.apache.shardingsphere.driver.executor.JDBCLockEngine.doExecute(JDBCLockEngine.java:116)
        at 
org.apache.shardingsphere.driver.executor.JDBCLockEngine.execute(JDBCLockEngine.java:93)
        at 
org.apache.shardingsphere.driver.executor.DriverJDBCExecutor.execute(DriverJDBCExecutor.java:127)
        at 
org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:298)
        at 
org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
        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 
org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:194)
        at 
org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:181)
        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.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:427)
        ... 37 more
   
   


-- 
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