File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Duplicate primary key in hibernate concurrent insert in table with auto generated primary key. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Duplicate primary key in hibernate concurrent insert in table with auto generated primary key." Watch "Duplicate primary key in hibernate concurrent insert in table with auto generated primary key." New topic
Author

Duplicate primary key in hibernate concurrent insert in table with auto generated primary key.

Vijay Kumar Raman
Greenhorn

Joined: Oct 19, 2010
Posts: 12
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.
Rajit vreddi
Greenhorn

Joined: Jul 05, 2012
Posts: 17
Use transaction while inserting and use flush then commit transaction.This might solve your problem.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Duplicate primary key in hibernate concurrent insert in table with auto generated primary key.
 
Similar Threads
Know auto incremented pimary key
can we get the preset auto-increment number before any insertion
Auto increment key in Hibernate
One to many insert with iBatis
hibernate one-many example issue