ShardingJdbcException: Cannot find table rule and default data source with logic tables: '[]'

skyyan2000 发布于 2018/07/04 13:07
阅读 586
收藏 0

 问题 

1.5.4 sharding-jdbc ,单库 ,有一部分 分表,其余的部分表

<dependency>
      <groupId>com.dangdang</groupId>
      <artifactId>sharding-jdbc-core</artifactId>
       
      <version>1.5.4</version>
   </dependency>
   <dependency>
      <groupId>com.dangdang</groupId>
      <artifactId>sharding-jdbc-config-spring</artifactId>

      <version>1.5.4</version>
   </dependency>
   <!--主键生成-->
   <dependency>
   <groupId>com.dangdang</groupId>
   <artifactId>sharding-jdbc-self-id-generator</artifactId>
   <version>1.4.2</version>
</dependency>
<!-- 分表 -->
<rdb:strategy id="tableShardingStrategy" sharding-columns="uid" algorithm-class="com.smartwork.msip.business.shard.impl.shardstrategy.AccountRelationTableShardingAlgorithm" />

<rdb:data-source id="shardingDataSourceMaster">
    <rdb:sharding-rule data-sources="dataSourceCoreMaster" default-data-source="dataSourceCoreMaster1"  >
        <rdb:table-rules>
            <rdb:table-rule logic-table="user_relation" actual-tables="user_relation_00,user_relation_01,user_relation_02"  table-strategy="tableShardingStrategy"/>
            <rdb:table-rule logic-table="short_video" actual-tables="short_video_00,short_video_01,short_video_02"  table-strategy="tableShardingStrategy"/>
        </rdb:table-rules>
       <!-- <rdb:default-table-strategy sharding-columns="uid" algorithm-class="com.smartwork.msip.business.shard.impl.shardstrategy.AccountRelationTableShardingAlgorithm" />-->
        <!--默认不分表-->
        <rdb:default-database-strategy sharding-columns="none" algorithm-class="com.dangdang.ddframe.rdb.sharding.api.strategy.database.NoneDatabaseShardingAlgorithm"/>
       <!-- <rdb:default-table-strategy sharding-columns="none" algorithm-class="com.dangdang.ddframe.rdb.sharding.api.strategy.table.NoneTableShardingAlgorithm"/>-->
    </rdb:sharding-rule>
    <rdb:props>
        <prop key="metrics.enable">false</prop>
    </rdb:props>
</rdb:data-source>

其中在保存不分表的数据的时候 报 如下错误

org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.ExecutorException: Error selecting key or setting result to parameter object. Cause: com.dangdang.ddframe.rdb.sharding.exception.ShardingJdbcException: Cannot find table rule and default data source with logic tables: '[]'
    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:75) ~[mybatis-spring-1.2.2.jar:1.2.2]
    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:371) ~[mybatis-spring-1.2.2.jar:1.2.2]
    at com.sun.proxy.$Proxy16.insert(Unknown Source) ~[na:na]
    at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240) ~[mybatis-spring-1.2.2.jar:1.2.2]
    at com.mtr.toplines.business.account.dao.AccountDao.insert(AccountDao.java:97) ~[msip_mtr_business_ds-1.0.jar:na]
    at com.mtr.toplines.business.account.dao.AccountDao.insert(AccountDao.java:18) ~[msip_mtr_business_ds-1.0.jar:na]

 

加载中
0
skyyan2000
skyyan2000

已解决 

是用自增主键 所造成的问题,把这个去掉 ,换成自己生成的唯一主键 即可

<!--<selectKey keyProperty="id" resultType="java.lang.Integer"
         order="AFTER">
         select last_insert_id();
      </selectKey>-->

 

0
小浣熊真帅

怎么解决的、我也这个问题,但是我主键不是自增的

返回顶部
顶部