数据入库出现主键id重复问题

Blade 已结 1 120
lifeCoder
lifeCoder 2025-08-04 17:13
悬赏:5

一、该问题的重现步骤是什么?

1. 两个云服务器部署了4个IOT服务

2. 网关将请求分流到四个服务器

3.所有服务共用的一个数据库

4.使用jmeter压力测试请求服务接口

5.id字段的信息:

(description = )
(value = , type = .)
(using = .)
;

二、你期待的结果是什么?实际看到的又是什么?

需求:bladex如何解决多个服务出现的数据入库主键id重复问题?

问题:同时处理的请求过多,出现主键id重复

Snipaste_2025-08-04_17-12-54.png

三、你正在使用的是什么产品,什么版本?在什么操作系统上?

产品:bladex

版本:4.5.0

系统:linux

四、请提供详细的错误堆栈信息,这很重要。

Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sixsigma_scar_pkey"

Detail: Key (id)=(1951651165988499458) already exists.

The error may exist in org/springblade/iot/mapper/StationAccessRecordMapper.java (best guess)

The error may involve org.springblade.iot.mapper.StationAccessRecordMapper.insert-Inline

The error occurred while setting parameters

SQL: INSERT INTO sixsigma_station_access_record (id, station_name, channel_no, ph_no, tenant_id, device_name, device_code, device_ip, card_no, card_color, brand, access_type, access_time, pic_url, feature_picture_url, create_time, update_time, status, is_deleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sixsigma_scar_pkey"

Detail: Key (id)=(1951651165988499458) already exists. ; ERROR: duplicate key value violates unique constraint "sixsigma_scar_pkey" Detail: Key (id)=(1951651165988499458) already exists.`


Error updating database.  Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sixsigma_scar_pkey"

Detail: Key (id)=(1951651165988499458) already exists.

The error may exist in org/springblade/iot/mapper/StationAccessRecordMapper.java (best guess)

The error may involve org.springblade.iot.mapper.StationAccessRecordMapper.insert-Inline

The error occurred while setting parameters

SQL: INSERT INTO sixsigma_station_access_record (id, station_name, channel_no, ph_no, tenant_id, device_name, device_code, device_ip, card_no, card_color, brand, access_type, access_time, pic_url, feature_picture_url, create_time, update_time, status, is_deleted) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)

Cause: org.postgresql.util.PSQLException: ERROR: duplicate key value violates unique constraint "sixsigma_scar_pkey"

Detail: Key (id)=(1951651165988499458) already exists. ; ERROR: duplicate key value violates unique constraint "sixsigma_scar_pkey" Detail: Key (id)=(1951651165988499458) already exists. at org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator.doTranslate(SQLErrorCodeSQLExceptionTranslator.java:254) at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:107) at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:93) at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:347) at jdk.proxy2/jdk.proxy2.$Proxy151.insert(Unknown Source) at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:224) at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:59) at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(Mybati


五、若有更多详细信息,请在下面提供。



1条回答
提交回复