[seata]插入数据时不指定主键报错SQL state [null]; error code [0];

2024-04-28 250 views
3

这是我的插入SQL;

insert into icloud_user_picture (
        folder_id,
        user_id,
        picture_name,
        picture_path,
        picture_size,
        picture_time,
        picture_status
        )
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.folderId},#{item.userId},#{item.pictureName},
            #{item.picturePath},#{item.pictureSize},#{item.pictureTime},
            #{item.pictureStatus}
            )
        </foreach>

报错信息:

 uncategorized SQLException; SQL state [null]; error code [0]; io.seata.common.exception.ShouldNeverHappenException; nested exception is java.sql.SQLException: io.seata.common.exception.ShouldNeverHappenException] with root cause
io.seata.common.exception.ShouldNeverHappenException: null
    at io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor.getPkValuesByAuto(MySQLInsertExecutor.java:121)
    at io.seata.rm.datasource.exec.mysql.MySQLInsertExecutor.getPkValues(MySQLInsertExecutor.java:81)

我的主键是用的美团leaf分布式ID,使用shardingsphere4.1.1自动生成的;

回答

8

你sql里没有插入主键,即便是shardingsphere生成的,实际的pk也是会放到sql中(可能被ss代理后改动sql,物理sql中存在pk),而不是没有 确认下你是否存在重复代理数据源,使用shardingsphere不需要开启自动代理

7

@a364176773

seata:
  registry:
    type: nacos
    nacos:
      server-addr: 192.168.0.202:8848,192.168.0.203:8848,192.168.0.204:8848
      namespace: be18794e-f6bc-4bb5-aba0-2379e4e5e86d
      username: nacos
      password: nacos
      group: SEATA_GROUP
  config:
    type: nacos
    nacos:
      server-addr: 192.168.0.202:8848,192.168.0.203:8848,192.168.0.204:8848
      group: SEATA_GROUP
      username: nacos
      password: nacos
      namespace: be18794e-f6bc-4bb5-aba0-2379e4e5e86d
  tx-service-group: camera-icloud-tx-group
  application-id: camera-icloud

我没有开启use-jdk-proxy,他默认也是false的

1

seata.enable-auto-data-source-proxy=false

3

用这个之后,事物不生效了,但是ID确实自动生成出来的;

3

不生效是因为你没按sharding-jdbc那套对接流程成功对接,按他们那边的sample来

6

感谢您的解答; 我例子是从https://gitee.com/seata-io/seata-samples.git照搬的; 里面有一个springcloud-seata-sharding-jdbc-mybatis-plus-samples工程; 他在seata-order-sample工程(使用了shardingjdbc配置文件seata.enable-auto-data-source-proxy=false)发送请求到seata-product-sample(普通数据源,此处使用了自动代理数据源); 我的情况是从:普通数据源--->sharding-jdbc分库分表; 这个错误是我跟源码看到的,您可以参考一下这个人提出的问题我跟他碰到一样的https://blog.csdn.net/jll126/article/details/122217789 @a364176773