Cause: java.lang.IllegalArgumentException: Sharding value must implements Comparable
2021/9/30 11:12:50
本文主要是介绍Cause: java.lang.IllegalArgumentException: Sharding value must implements Comparable,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
在使用sharding jdbc 进行 分库分表时 插入语句 遇到如下错误
错误如下
Caused by: org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: java.lang.IllegalArgumentException: Sharding value must implements Comparable. ### The error may exist in com/style/note/sharding/mapper/OrderGoodsMapper.java (best guess) ### The error may involve com.style.note.sharding.mapper.OrderGoodsMapper.insert-Inline ### The error occurred while setting parameters ### SQL: insert into t_order_goods(user_id,order_sn,goods_name,price,gmt_create,gmt_update) values(?,?,?,?,?,?) ### Cause: java.lang.IllegalArgumentException: Sharding value must implements Comparable. 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:427) ... 50 more Caused by: java.lang.IllegalArgumentException: Sharding value must implements Comparable. at com.google.common.base.Preconditions.checkArgument(Preconditions.java:144) at org.apache.shardingsphere.sharding.route.engine.condition.engine.InsertClauseShardingConditionEngine.getRouteValue(InsertClauseShardingConditionEngine.java:112) at org.apache.shardingsphere.sharding.route.engine.condition.engine.InsertClauseShardingConditionEngine.createShardingCondition(InsertClauseShardingConditionEngine.java:94) at
代码如图
OrderGoods orderGoods = new OrderGoods(); //orderGoods.setUserId((long) i); orderGoods.setOrderSn(order.getOrderSn()); orderGoods.setGoodsName("AAA"); orderGoods.setPrice(BigDecimal.valueOf(200)); orderGoods.setGmtCreate(instance.getTime()); orderGoods.setGmtUpdate(instance.getTime()); orderGoodsService.addOrderGoods(orderGoods);
注释的代码后面才补上 之前是没有的
因为order_goods表 根据user_id 进行分库 这个值没有设置就会出错了
总结一下这个错误的原因
- 被用来分片的键不能为空
- 可能该键为自生成ID 但这个自生成ID没有生效也就是没有生成成功
- 其他错误原因引起
这篇关于Cause: java.lang.IllegalArgumentException: Sharding value must implements Comparable的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28AI给的和自己写的Python代码,都无法改变输入框的内容,替换也不行
- 2024-09-27Sentinel配置限流资料:新手入门教程
- 2024-09-27Sentinel配置限流资料详解
- 2024-09-27Sentinel限流资料:新手入门教程
- 2024-09-26Sentinel限流资料入门详解
- 2024-09-26Springboot框架资料:初学者入门教程
- 2024-09-26Springboot框架资料详解:新手入门教程
- 2024-09-26Springboot企业级开发资料:新手入门指南
- 2024-09-26SpringBoot企业级开发资料新手指南
- 2024-09-26Springboot微服务资料入门教程