• Post Reply Bookmark Topic Watch Topic
  • New Topic

Avoid StaleObjectStateException in hibernate for bidirectional relation

 
zabet tyan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have the following problem:

I have a class Group



and a class Profile:





Here is the related section of hbm file for Group



and for Profile:




Now I want to add a group to profile and add the profile to that group:




The problem is that I can never update the bi-direlational relation because I get StaleObjectException as soon as I try to update the second part of the relation.

Any suggestions on what I can do to avoid this problem without breaking the relation?

Do I have to load the Profile again from the database before I add the Profile to Group and save?


Any help is appreciated.
 
zabet tyan
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK solved it... just had to remove cascade="all" from Group.hbm.xml



 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!