开发者社区> 问答> 正文

sharding-jdbc.1.5.0 配置default-data-source无效?报错

 

数据源配置:

<bean id="dataSource" class="com.qbao.dling.dao.datasource.QbaoDataSource" ><!-- 读写分离配置 -->
   <property name="targetDataSources">
      <map key-type="java.lang.String">
         <entry value-ref="MASTER_TV_DATA_SOURCE" key="MASTER_TV_DATA_SOURCE"></entry>
         <entry value-ref="SLAVE_TV_DATA_SOURCE" key="SLAVE_TV_DATA_SOURCE"></entry>
      </map>
   </property>
   <property name="defaultTargetDataSource" ref="MASTER_TV_DATA_SOURCE" >
   </property>
</bean>

<rdb:strategy id="clockAlgorithm" sharding-columns="user_id" algorithm-class="com.qbao.dling.qbaolive.argorithm.SingleKeyModuloTableShardingAlgorithm" />
<rdb:data-source id="shardingDataSource" >
   <rdb:sharding-rule data-sources="dataSource" default-data-source="dataSource">
      <rdb:table-rules>
         <rdb:table-rule logic-table="td_clock_log" actual-tables="td_clock_log_0${0..9}" table-strategy="clockAlgorithm" />
      </rdb:table-rules>
   </rdb:sharding-rule>
</rdb:data-source>

执行的SQL:

<insert id="add" parameterType="TvShieldInfo">
    <selectKey resultType="long" order="AFTER" keyProperty="id">
        SELECT LAST_INSERT_ID() AS id
    </selectKey>
    INSERT INTO td_broadcast_shield_info
    (user_id,shield_user_id,state,create_time,update_time)
    VALUES(#{userId},#{shieldUserId},#{state},now(),now())
</insert>

应该是SELECT LAST_INSERT_ID() AS id引起的问题。

jdk:1.7

报错信息:

展开
收起
爱吃鱼的程序员 2020-06-08 11:48:03 636 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    不支持SELECTLAST_INSERT_ID()

    使用分表库分表后也不建议在使用MySQL原生的自增主键,这样做不到分布式主键不冲突

    没有参与分表的也无法使用主键返回吗?除了订单表和订单详情是分表的。其他表不分表,需要返回id做关联,怎么处理?明白,感谢亮哥解答

    同问default-data-source无效。

    2020-06-08 11:48:22
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
How to Build a Successful Data 立即下载
MongoShake -- Multi Active-Active and Cross-Region Disaster Recoverable MongoDB Service 立即下载
Using Hadoop to build a Data Quality Service for both real-time and batch data 立即下载