有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Hibernate合并函数偶尔会导致主键冲突

我们正在Java应用程序中使用Hibernate。要更新特定信息(及其所有相关依赖项),我们使用Hibernate合并功能:

HibernateTemplate template = getHibernateTemplate();
template.deleteAll(toBeDeletedObjs);
Object mergedObj = template.merge(obj);

正在更新的主表有5列,第一列(主键)是自动生成的值

偶尔,但并非总是,合并的插入会出现以下错误:

[在表中插入(COL1、COL2、COL3、COL4、COL5)值(默认值、、、?、?)

DuplicateKeyException: One or more values in the INSERT statement, UPDATE statement, or foreign key update caused by a DELETE statement are not valid because the primary key, unique constraint or unique index identified by "ID" constrains table "TABLE" from having duplicate values for the index key.. SQLCODE=-803, SQLSTATE=23505, DRIVER=3.53.95

我假设“default”是自动生成的Hibernate值,所以我没有检索前一个对象的ID;这不可能是错误的原因。有没有想过为什么Hibernate有时会失败


共 (0) 个答案