Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Hibernate primary key generation policy strategy = "increment" error violation uniqueness constraint

Shulou Source: shulou.com Published: 2022-06-03 04:27:37 10月04日 Update

Background

In July 2018, the system burst a bug. Is to support the Excel import function, import the second time different from the template of data, report an error, in violation of the uniqueness constraint. It is useless to restart Tomcat before it can be used again. But only to one file.

Analysis.

Tomcat needs to be restarted, which should be due to the cache.

Reason

After analyzing all the code, the temporary data is changed from clear to new. No.

Memory usage monitoring, after importing the template, it will return to normal, not

Finally, looking at the exception to find the cause, it is found that the primary key strategy of Hibernate is strategy = "increment".

Try

Could it be that the hibernate primary key policy is selected incorrectly, because the selected primary key policy simply cannot be deleted.

Collect

All primary key policies of Hibernate

Https://www.cnblogs.com/hoobey/p/5508992.html

Solve

Select the program to automatically generate the primary key strategy, and strategy = "assigned" after adjustment

Tags: Policies reasons that is data templates analysis selection uniqueness generation different no code memory functions cause analysis files months life and death programs systems Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Apple MariaDB vpn