Duplicate primary key in hibernate concurrent insert in table with auto generated primary key.
Vijay Kumar Raman
posted 5 years ago
How to prevent duplicate data entry in hibernate while more than one insertion done being simultaneously (by two different processes) that have auto generated primary key?
Our application will insert record to a mysql table with auto generated primary key and using hibernate 3 and MYSQL 5.5.21. But when the same application is running in more than one PC and both trying to insert record in the table simultaneously, I get the exception as below
org.hibernate.util.JDBCExceptionReporter:logExceptions(78) | Duplicate entry 'somevalue' for key 'PRIMARY'.
Kindly help to resolve this issue.
posted 4 years ago
Use transaction while inserting and use flush then commit transaction.This might solve your problem.