Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A different object with the same identifier?

 
Darren Carter
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 543
4
Java Netbeans IDE Redhat
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().
 
Darren Carter
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic