• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use transaction while inserting and use flush then commit transaction.This might solve your problem.
 
reply
    Bookmark Topic Watch Topic
  • New Topic