Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Avoid StaleObjectStateException in hibernate for bidirectional relation  RSS feed

 
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



 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!