You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2021/07/13 01:41:55 UTC

[GitHub] [shardingsphere] 2241101100 opened a new issue #11299: "Cannot find strategy for generate keys." error when mybatis-plus save

2241101100 opened a new issue #11299:
URL: https://github.com/apache/shardingsphere/issues/11299


   **springboot:2.2.12 mybatis-plus:3.4.1 shardingsphere-jdbc-core-spring-boot-starter:5.0.0-beta**
   
   code:
   ```
   @Data
   @ApiModel(description = "系统访问记录")
   @TableName(value = "sys_logininfor")
   public class SysLogininforEntity implements Serializable{
   
       /** 版本号 */
       private static final long serialVersionUID = 5144668849088694164L;
   
   	@ApiModelProperty(value = "访问ID")
   	@TableId(value = "info_id", type = IdType.AUTO)
   	private Integer infoId;
   	
   	@ApiModelProperty(value = "用户账号")
   	@TableField(value="user_name")
   	private String userName;
           ......
   }
   
   ```
   
   
   
   configurations:
   ```
   spring:
     shardingsphere:
       datasource:
         names: ds0,ds1
         ds0:
           jdbc-url: jdbc:mysql://127.0.0.1:3306/sb_1?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=Asia/Shanghai
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.jdbc.Driver
           username: root
           password: root
         ds1:
           jdbc-url: jdbc:mysql://127.0.0.1:3306/sb_2?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimeZone=Asia/Shanghai
           type: com.zaxxer.hikari.HikariDataSource
           driver-class-name: com.mysql.jdbc.Driver
           username: root
           password: root
       rules:
         sharding:
           sharding-algorithms:
             table-inline:
               type: INLINE
               props:
                 algorithm-expression: wx_user_$->{ id % 10 }
                 allow-range-query-with-inline-sharding: true
             table-interval:
               type: INTERVAL
               props:
                 datetime-pattern: 'yyyy-MM-dd HH:mm:ss'
                 datetime-lower: '1970-01-01 00:00:00'
                 datetime-upper: '2050-12-31 23:59:59'
                 sharding-suffix-pattern: 'yyyy_MM'
                 datetime-interval-amount: 1
                 datetime-interval-unit: MONTHS
           key-generators:
             snowflake:
               type: SNOWFLAKE
               props:
                 worker-id: 1
           tables:
             -wx_user:
               actual-data-nodes: prds.wx_user_$->{0..9}
               table-strategy:
                 standard:
                   sharding-column: id
                   sharding-algorithm-name: table-inline
             -t_split_time:
               actual-data-nodes: prds.t_split_time_$->{1970..2050}_$->{['01','02','03','04','05','06','07','08','09','10','11','12']}
               table-strategy:
                 standard:
                   sharding-column: create_time
                   sharding-algorithm-name: table-interval
         replica-query:
           load-balancers:
             -round-robin:
               type: ROUND_ROBIN
               props:
                 default: ds0
           data-sources:
             -prds:
               primary-data-source-name: ds0
               replica-data-source-names: ds0
               load-balancer-name: round_robin
       enabled: true
       props:
         sql-show: true
   ```
   
   
   
   log:
   ```
   Cause: org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException: Cannot find strategy for generate keys.
   	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:199)
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184)
   	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:426)
   	... 147 common frames omitted
   Caused by: org.apache.shardingsphere.infra.config.exception.ShardingSphereConfigurationException: Cannot find strategy for generate keys.
   	at org.apache.shardingsphere.sharding.rule.ShardingRule.generateKey(ShardingRule.java:433)
   	at org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine.lambda$generateKeys$0(InsertClauseShardingConditionEngine.java:133)
   	at java.util.stream.IntPipeline$4$1.accept(IntPipeline.java:250)
   	at java.util.stream.Streams$RangeIntSpliterator.forEachRemaining(Streams.java:110)
   	at java.util.Spliterator$OfInt.forEachRemaining(Spliterator.java:693)
   	at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481)
   	at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471)
   	at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708)
   	at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
   	at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499)
   	at org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine.generateKeys(InsertClauseShardingConditionEngine.java:133)
   	at org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine.appendGeneratedKeyConditions(InsertClauseShardingConditionEngine.java:125)
   	at org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine.createShardingConditions(InsertClauseShardingConditionEngine.java:63)
   	at org.apache.shardingsphere.sharding.route.engine.condition.engine.impl.InsertClauseShardingConditionEngine.createShardingConditions(InsertClauseShardingConditionEngine.java:52)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createShardingConditions(ShardingSQLRouter.java:71)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:56)
   	at org.apache.shardingsphere.sharding.route.engine.ShardingSQLRouter.createRouteContext(ShardingSQLRouter.java:47)
   	at org.apache.shardingsphere.infra.route.engine.impl.PartialSQLRouteExecutor.route(PartialSQLRouteExecutor.java:62)
   	at org.apache.shardingsphere.infra.route.engine.SQLRouteEngine.route(SQLRouteEngine.java:52)
   	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:363)
   	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:271)
   	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:47)
   	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:74)
   	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.$Proxy230.update(Unknown Source)
   	at com.baomidou.mybatisplus.core.executor.MybatisSimpleExecutor.doUpdate(MybatisSimpleExecutor.java:56)
   	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117)
   	at com.baomidou.mybatisplus.core.executor.MybatisCachingExecutor.update(MybatisCachingExecutor.java:85)
   	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.Invocation.proceed(Invocation.java:49)
   	at com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor.intercept(MybatisPlusInterceptor.java:83)
   	at org.apache.ibatis.plugin.Plugin.invoke(Plugin.java:61)
   	at com.sun.proxy.$Proxy229.update(Unknown Source)
   	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197)
   	... 153 common frames omitted
   
   ```
   
   
   
   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] 2241101100 commented on issue #11299: "Cannot find strategy for generate keys." error when mybatis-plus save

Posted by GitBox <gi...@apache.org>.
2241101100 commented on issue #11299:
URL: https://github.com/apache/shardingsphere/issues/11299#issuecomment-878710899


   but 5.0.0-alpha doesn't have this problem


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu commented on issue #11299: "Cannot find strategy for generate keys." error when mybatis-plus save

Posted by GitBox <gi...@apache.org>.
terrymanu commented on issue #11299:
URL: https://github.com/apache/shardingsphere/issues/11299#issuecomment-927272469


   Closed because of no response


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] terrymanu closed issue #11299: "Cannot find strategy for generate keys." error when mybatis-plus save

Posted by GitBox <gi...@apache.org>.
terrymanu closed issue #11299:
URL: https://github.com/apache/shardingsphere/issues/11299


   


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [shardingsphere] strongduanmu commented on issue #11299: "Cannot find strategy for generate keys." error when mybatis-plus save

Posted by GitBox <gi...@apache.org>.
strongduanmu commented on issue #11299:
URL: https://github.com/apache/shardingsphere/issues/11299#issuecomment-878809065


   @2241101100 Which table query triggered this exception? If the table cannot find the corresponding table rule, this exception will occur.
   
   ```java
       /**
        * Generate key.
        *
        * @param logicTableName logic table name
        * @return generated key
        */
       public Comparable<?> generateKey(final String logicTableName) {
           Optional<TableRule> tableRule = findTableRule(logicTableName);
           if (!tableRule.isPresent()) {
               throw new ShardingSphereConfigurationException("Cannot find strategy for generate keys.");
           }
           KeyGenerateAlgorithm keyGenerator = null != tableRule.get().getKeyGeneratorName() ? keyGenerators.get(tableRule.get().getKeyGeneratorName()) : defaultKeyGenerateAlgorithm;
           return keyGenerator.generateKey();
       }
   ```


-- 
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: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org