报错信息:
Error flushing statements. Cause: org.apache.ibatis.executor.BatchExecutorException: com.sifang.web.devicehealthanalysis.model.mapper.TypeDeviceMapper.insert (batch index #1) failed. Cause: java.sql.BatchUpdateException: errCode = 2, detailMessage = Unknown table 'type_device'

注释的saveBatch报错,找不到type_device表。
试了试save,好使的。
观察表结构,发现这张表没有id。不知道有没有关系?
2024-05-13
已验证,和表没有id没有关系。
正确原因如下:
数据库配置如下:
#数据库配置信息
datasource:
dynamic:
strict: true
lazy: false
primary: cdf
datasource:
master:
url: jdbc:postgresql://192.178.10.46:5432/postgres?currentSchema=cdf
username: postgres
password: postgres
driver-class-name: org.postgresql.Driver
doris:
url: jdbc:mysql://192.188.32.40:9030/sds
username: sds
password: sds
driver-class-name: com.mysql.cj.jdbc.Driver
dsv:
url: jdbc:postgresql://192.178.10.46:5432/smartsys?currentSchema=dsv
username: dsv
password: dsv
driver-class-name: org.postgresql.Driver
cdf:
url: jdbc:postgresql://192.178.10.46:5432/smartsys?currentSchema=cdf
username: cdf
password: cdf
driver-class-name: org.postgresql.Driver
@DS("smartsys")
public interface ParaBreakerMapper extends BaseMapper<ParaBreaker> {
List<ParaBreaker> findParaBreakerById(Long id);
}
public interface TypeDeviceService extends IService<TypeDevice> {
}
我在mapper配置了DS注解是采用的cdf这个数据源,我把配置文件中的primary改为cdf就能用了。
发现我的service没有配置数据源,会加载primary的数据源。之所以报错,是因为service和mapper的数据源加载的不一样。如果我的方法涉及到mapper层就不会报错,就能找到我的表。如果我直接使用service封装好的方法,就会去加载Primary的数据源,找不到表。
解决方法:
在service层加DS注解




被折叠的 条评论
为什么被折叠?



