欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Sharding-jdbc報(bào)錯(cuò):Missing the data source name:‘m0‘解決方案

 更新時(shí)間:2024年11月04日 08:49:31   作者:在奮斗的大道  
在使用MyBatis-plus進(jìn)行數(shù)據(jù)操作時(shí),新增Order實(shí)體屬性后,出現(xiàn)了數(shù)據(jù)源缺失的提示錯(cuò)誤,原因是因?yàn)閡serId屬性值使用了隨機(jī)函數(shù)生成的Long值,這與sharding-jdbc的路由規(guī)則計(jì)算不匹配,導(dǎo)致無法找到正確的數(shù)據(jù)源,通過調(diào)整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 實(shí)體屬性時(shí),提示Missing the data source name: 'm0'

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

調(diào)整后的插入功能代碼:

@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 "批量新增成功";
	}

總結(jié)

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論