This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes SEVERE: Duplicate entry '1' for key 'PRIMARY' Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "SEVERE: Duplicate entry Watch "SEVERE: Duplicate entry New topic

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

shankhas sanyal
Ranch Hand

Joined: Jun 15, 2008
Posts: 45
hi all,
I am very new to hibernate and I am following a simple one to many example that I found on "".

these are my tables :

my hibernate.cfg.xml


this my bean:

this my student.hbm.xml:

my 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!!!

I love this place!
shankhas sanyal
Ranch Hand

Joined: Jun 15, 2008
Posts: 45
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: SEVERE: Duplicate entry '1' for key 'PRIMARY'
jQuery in Action, 3rd edition