This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Modern JavaScript for the Impatient and have Cay Horstmann on-line!
See this thread for details.
Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

SEVERE: Duplicate entry '1' for key 'PRIMARY'

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I am very new to hibernate and I am following a simple one to many example that I found on "Vaannila.com".

these are my tables :


my hibernate.cfg.xml



my HibernateUtil.java


this my student.java bean:



this my student.hbm.xml:


my phone.java bean




my phone.hbm.xml



my main method class:




my complete output:



can some please explain to me why i am getting a duplicate entry exception?

Thank You!!!
Shankha
 
shankhas sanyal
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have fixed this....
apparently this application is trying to add multiple records of the same record to the join table
and since there are multiple entries to student id and phone id in the jointable this is what is causing the problem. How to fix this?

1. remove all foreign keys on the join table
2. alter the join table
3. remove the primary key
4. add a new primary key with auto increment
5. save the table
6. run the project and now it runs properly without any errors and it inserts perfectly into the tables
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic