This week's book giveaway is in the Java in General forum. We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line! See this thread for details.
Duplicate primary key in hibernate concurrent insert in table with auto generated primary key.
Vijay Kumar Raman
posted 4 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 3 years ago
Use transaction while inserting and use flush then commit transaction.This might solve your problem.