lly835 opened a new issue #8392:
URL: https://github.com/apache/shardingsphere/issues/8392


   ## Bug Report
   
   **For English only**, other languages will not accept.
   
   Before report a bug, make sure you have:
   
   - Searched open and closed [GitHub 
issues](https://github.com/apache/shardingsphere/issues).
   - Read documentation: [ShardingSphere 
Doc](https://shardingsphere.apache.org/document/current/en/overview).
   
   Please pay attention on issues you submitted, because we maybe need more 
details. 
   If no response anymore and we cannot reproduce it on current information, we 
will **close it**.
   
   Please answer these questions before submitting your issue. Thanks!
   
   ### Which version of ShardingSphere did you use?
   ```
   
       <parent>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-parent</artifactId>
           <version>2.3.2.RELEASE</version>
       </parent>
   
           <dependency>
               <groupId>org.apache.shardingsphere</groupId>
               
<artifactId>shardingsphere-jdbc-core-spring-boot-starter</artifactId>
               <version>5.0.0-alpha</version>
           </dependency>
   ```
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC
   
   ### Expected behavior
   
   ### Actual behavior
   ```
   
           OrderEntity byOrderId = orderDao.findByOrderId(1606492043640l);
           log.info("byOrderId={}", byOrderId);
   
           byOrderId.setRemark("remark");
           orderDao.save(byOrderId);
   ```
   
   ```
   
   2020-11-28 00:38:18.372  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Logic SQL: select orderentit0_.id as id1_0_, 
orderentit0_.order_id as order_id2_0_, orderentit0_.remark as remark3_0_, 
orderentit0_.user_id as user_id4_0_ from t_order orderentit0_ where 
orderentit0_.order_id=?
   2020-11-28 00:38:18.372  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : SQLStatement: 
MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty)
   2020-11-28 00:38:18.372  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds0 ::: select orderentit0_.id as id1_0_, 
orderentit0_.order_id as order_id2_0_, orderentit0_.remark as remark3_0_, 
orderentit0_.user_id as user_id4_0_ from t_order_0 orderentit0_ where 
orderentit0_.order_id=? ::: [1606492043640]
   2020-11-28 00:38:18.372  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds1 ::: select orderentit0_.id as id1_0_, 
orderentit0_.order_id as order_id2_0_, orderentit0_.remark as remark3_0_, 
orderentit0_.user_id as user_id4_0_ from t_order_0 orderentit0_ where 
orderentit0_.order_id=? ::: [1606492043640]
   2020-11-28 00:38:18.445  INFO 51536 --- [           main] 
c.i.d.DistributedShardingApplicationTest : 
byOrderId=OrderEntity(id=539229976252624896, orderId=1606492043640, userId=837, 
remark=null)
   2020-11-28 00:38:18.467  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Logic SQL: select orderentit0_.id as id1_0_0_, 
orderentit0_.order_id as order_id2_0_0_, orderentit0_.remark as remark3_0_0_, 
orderentit0_.user_id as user_id4_0_0_ from t_order orderentit0_ where 
orderentit0_.id=?
   2020-11-28 00:38:18.468  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : SQLStatement: 
MySQLSelectStatement(limit=Optional.empty, lock=Optional.empty)
   2020-11-28 00:38:18.468  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds0 ::: select orderentit0_.id as id1_0_0_, 
orderentit0_.order_id as order_id2_0_0_, orderentit0_.remark as remark3_0_0_, 
orderentit0_.user_id as user_id4_0_0_ from t_order_0 orderentit0_ where 
orderentit0_.id=? ::: [539229976252624896]
   2020-11-28 00:38:18.468  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds0 ::: select orderentit0_.id as id1_0_0_, 
orderentit0_.order_id as order_id2_0_0_, orderentit0_.remark as remark3_0_0_, 
orderentit0_.user_id as user_id4_0_0_ from t_order_1 orderentit0_ where 
orderentit0_.id=? ::: [539229976252624896]
   2020-11-28 00:38:18.468  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds1 ::: select orderentit0_.id as id1_0_0_, 
orderentit0_.order_id as order_id2_0_0_, orderentit0_.remark as remark3_0_0_, 
orderentit0_.user_id as user_id4_0_0_ from t_order_0 orderentit0_ where 
orderentit0_.id=? ::: [539229976252624896]
   2020-11-28 00:38:18.468  INFO 51536 --- [           main] ShardingSphere-SQL 
                      : Actual SQL: ds1 ::: select orderentit0_.id as id1_0_0_, 
orderentit0_.order_id as order_id2_0_0_, orderentit0_.remark as remark3_0_0_, 
orderentit0_.user_id as user_id4_0_0_ from t_order_1 orderentit0_ where 
orderentit0_.id=? ::: [539229976252624896]
   
   org.springframework.transaction.TransactionSystemException: Could not commit 
JPA transaction; nested exception is javax.persistence.RollbackException: Error 
while committing the transaction
   
        at 
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:543)
        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:633)
        at 
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:386)
        at 
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:118)
        at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at 
org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at 
org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:178)
        at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at 
org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:95)
        at 
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at 
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy95.save(Unknown Source)
        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.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
        at 
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:205)
        at com.sun.proxy.$Proxy98.save(Unknown Source)
        at 
com.imooc.distributedsharding.DistributedShardingApplicationTest.find(DistributedShardingApplicationTest.java:39)
        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:68)
        at 
com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
        at 
com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:230)
        at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:58)
   Caused by: javax.persistence.RollbackException: Error while committing the 
transaction
        at 
org.hibernate.internal.ExceptionConverterImpl.convertCommitException(ExceptionConverterImpl.java:81)
        at 
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:104)
        at 
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:534)
        ... 53 more
   Caused by: 
org.apache.shardingsphere.infra.exception.ShardingSphereException: Can not 
update sharding key, logic table: [t_order], column: [order_id].
        at 
org.apache.shardingsphere.sharding.route.engine.validator.dml.impl.ShardingUpdateStatementValidator.preValidate(ShardingUpdateStatementValidator.java:64)
        at 
org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.lambda$createRouteContext$0(ShardingSQLRouter.java:63)
   
   ```
   
   i don't set sharding for 'remark'
   ```
   
   @Entity
   @Table(name = "t_order")
   @Data
   public class OrderEntity {
   
       @Id
       @GeneratedValue(strategy = GenerationType.IDENTITY)
       private Long id;
   
       private Long orderId;
   
       private Integer userId;
   
       private String remark;
   }
   
   ```
   
   ```
   
   # 配置 t_order 表规则
   
spring.shardingsphere.rules.sharding.tables.t_order.actual-data-nodes=ds$->{0..1}.t_order_$->{0..1}
   
   # 配置分库策略
   
spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-column=user_id
   
spring.shardingsphere.rules.sharding.tables.t_order.database-strategy.standard.sharding-algorithm-name=database-inline
   
   # 配置分表策略
   
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-column=order_id
   
spring.shardingsphere.rules.sharding.tables.t_order.table-strategy.standard.sharding-algorithm-name=table-inline
   
   # 配置 分片算法
   
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.type=INLINE
   
spring.shardingsphere.rules.sharding.sharding-algorithms.database-inline.props.algorithm-expression=ds$->{user_id
 % 2}
   
spring.shardingsphere.rules.sharding.sharding-algorithms.table-inline.type=INLINE
   
spring.shardingsphere.rules.sharding.sharding-algorithms.table-inline.props.algorithm-expression=t_order_$->{order_id
 % 2}
   
   spring.shardingsphere.props.sql-show=true
   
   
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.column=id
   
spring.shardingsphere.rules.sharding.tables.t_order.key-generate-strategy.key-generator-name=snowflake
   
   #为什么不配置这2行就启动失败?
   spring.shardingsphere.rules.sharding.key-generators.snowflake.type=SNOWFLAKE
   
spring.shardingsphere.rules.sharding.key-generators.snowflake.props.worker-id=123
   ```
   ### Reason analyze (If you can)
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   


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

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


Reply via email to