It's not a secret anymore!*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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
Bartender

Joined: Aug 06, 2010
Posts: 543
    
    4

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: (JEE 6 Web Component Developer && JEE 6 EJB 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?