Sharding-jdbc 提示:no table route info解析
无情
阅读:743
2021-03-31 12:52:29
评论:0
异常描述:
### Error updating database. Cause: java.lang.IllegalStateException: no table route info
### The error may exist in com/zzg/mapper/OrderMapper.java (best guess)
### The error may involve com.zzg.mapper.OrderMapper.insert-Inline
### The error occurred while setting parameters
### Cause: java.lang.IllegalStateException: no table route info] with root cause
java.lang.IllegalStateException: no table route info
异常造成原因:
@RequestMapping(value = "/batchInsert", method = { RequestMethod.GET })
public Object batchInsert() {
List<Order> orders = new ArrayList<Order>();
for (int i = 0; i < 10; i++) {
Order order = new Order();
order.setPrice(new BigDecimal(Math.random()));
order.setUserId(new Random().nextLong());
order.setStatus("0");
orders.add(order);
}
if(orders != null && orders.size() > 0){
orderService.saveBatch(orders);
}
return "批量新增成功";
}
使用mybatis-plus 默认批量处理,导致t_order 表无法获取表路由信息导致数据无法入库。
mybatsi-plus 批量处理的语法规则是:多条insert 语句使用分号进行分隔,但是sharding-jdbc 路由引擎会分析每一条执行的sql 语句,并根据用户配置的路由规则达到指定的表,但是多条语句批量插入仅仅会只有一条语句插入成功,其他的都会插入失败,因为无法找到表路由信息。
异常解决办法
在使用sharding-jdbc 分库分表的项目中,禁止使用批量新增、批量修改功能。
声明
1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。