fix: 修复自增主键并发线程问题

This commit is contained in:
lhc
2026-03-06 10:42:05 +08:00
parent f9bdbef6ad
commit 5d8dde90ae
3 changed files with 5 additions and 5 deletions

View File

@@ -9,7 +9,7 @@
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>hcframe-base</artifactId>
<version>1.2.5.3.2-SNAPSHOT</version>
<version>1.2.5.3.3-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>

View File

@@ -896,7 +896,7 @@ public class BaseMapperImpl implements BaseMapper {
if (map == null) {
tableMapper.createHighGoSequence(tableName.toLowerCase(), 1);
} else {
tableMapper.createHighGoSequence(tableName.toLowerCase(), map.get(pkName));
tableMapper.createHighGoSequence(tableName.toLowerCase(), Long.parseLong(String.valueOf(map.get(pkName)))+ 1);
}
}
id = tableMapper.getHighGoSequence(tableName.toLowerCase());
@@ -914,12 +914,12 @@ public class BaseMapperImpl implements BaseMapper {
if (map == null) {
tableMapper.createSequence(tableName, 1);
} else {
tableMapper.createSequence(tableName, map.get(pkName));
tableMapper.createSequence(tableName, Long.parseLong(String.valueOf(map.get(pkName)))+ 1);
}
id = tableMapper.getSequence(tableName);
}
}
return Long.parseLong(id.toString()) + 1L;
return Long.parseLong(id.toString());
}
private Map<String, Object> selectRecentData(String tableName, String pkName) {

View File

@@ -171,7 +171,7 @@
NOCACHE
</insert>
<insert id="createHighGoSequence">
CREATE SEQUENCE ${tableName}_seq
CREATE SEQUENCE IF NOT EXISTS ${tableName}_seq
MINVALUE 1
NO MAXVALUE
START WITH ${lastId}