This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Vijay Kumar Raman
Greenhorn
Posts: 12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use transaction while inserting and use flush then commit transaction.This might solve your problem.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic