File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes A different object with the same identifier? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "A different object with the same identifier?" Watch "A different object with the same identifier?" New topic
Author

A different object with the same identifier?

Darren Carter
Ranch Hand

Joined: Jul 08, 2010
Posts: 30
Hi,

I have a problem with hibernate, and im not understanding what is wrong.

I get the following error



So from what I understand hibernate is complaining because I am trying to save a different object of the same id, which has already been saved?..

My XML Mappings – One to Many




My DAO



So what I don’t understand is why hibernate thinks I have already saved the SocialAccount with that id already?

Can someone please help?

Dieter Quickfend
Ranch Hand

Joined: Aug 06, 2010
Posts: 359
Your userAccount is managed since you get it from the DB. Your SocialAccount, however, is not. If a SocialAccount with this id is already in the DB, it will throw this exception. Fix it by calling merge() instead of saveOrUpdate().


Oracle Certified Professional: Java SE 6 Programmer
Oracle Certified Expert: Java EE 6 Web Component Developer
Oracle Certified Expert: Java EE 6 Enterprise JavaBeans Developer
Darren Carter
Ranch Hand

Joined: Jul 08, 2010
Posts: 30
Hi Dieter,

Thank you for the advise and yes merge works. I now underatand that the mege will update the managed object from the unmanged object.

Thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A different object with the same identifier?
 
Similar Threads
hibernate association mistery
many side of one to many not being populated
spring+hibernate: insert data into database(one to many)
Querying tables with a one-to-many foreign key relationship
Hibernate - Force foreign key lookup on insert