File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes one to many relation error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "one to many relation error" Watch "one to many relation error" New topic

one to many relation error

rodrigo bengoechea

Joined: Nov 15, 2008
Posts: 10
Hi everyone! I�m newbe using Hibernate and I�m trying to figure out where�s my mistake mapping a one-to-may relation. I�ve been the last hours trying to solve it but I couldn�t, so I decided to ask you. Please any suggestion will help me a lot!!

I explain you the bussines logic here:
every user has one or more passwords, and a password can be removed from a user.

I know that my post it�s a quite long but I tried to provide you everything you should need...

So here�s the User class:

Here the Password class

Here the User mapping xml:

Here�s the hibernate config:

Here where I�m creating the user:

And finally here�s the stack trace:

Thanks in advance for your help!!!
joe sinnott

Joined: Nov 23, 2008
Posts: 4

At first glance it would seem that you are violating some database contraint.

Caused by: java.sql.BatchUpdateException: Duplicate entry '2' for key 1

It would appear that you are inserting into a table that already has a key value i.e. '2'
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: one to many relation error
It's not a secret anymore!