MybatisPlus多数据源batchInsert报错

报错信息:

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注解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值