亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Sharding-jdbc報錯:Missing the data source name:‘m0‘解決方案

 更新時間:2024年11月04日 08:49:31   作者:在奮斗的大道  
在使用MyBatis-plus進行數(shù)據(jù)操作時,新增Order實體屬性后,出現(xiàn)了數(shù)據(jù)源缺失的提示錯誤,原因是因為userId屬性值使用了隨機函數(shù)生成的Long值,這與sharding-jdbc的路由規(guī)則計算不匹配,導致無法找到正確的數(shù)據(jù)源,通過調整userId生成邏輯

異常描述

### Error updating database.  Cause: java.lang.IllegalStateException: Missing the data source name: 'm0'
### 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() {
	
		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");
			orderService.save(order);
		}
		
		return "批量新增成功";
	}

使用MyBatis-plus 新增Order 實體屬性時,提示Missing the data source name: 'm0'

造成原因是由于userId的屬性值,我使用的是隨機函數(shù)生成的Long 值進行填充,導致sharding-jdbc 路由引擎執(zhí)行分析時與自己定義的數(shù)據(jù)庫規(guī)則計算值異常導致輸出了一個不存在的數(shù)據(jù)源。

調整后的插入功能代碼:

@RequestMapping(value = "/batchInsert", method = { RequestMethod.GET })
	public Object batchInsert() {
		
		for (int i = 0; i < 10; i++) {
			Order order = new Order();
			order.setPrice(new BigDecimal(Math.random()));
			order.setUserId(Long.valueOf("" + i));
			order.setStatus("0");
			
			orderService.save(order);
		}
		

		return "批量新增成功";
	}

總結

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論