Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate error when deleting child objects when parent object is deleted

 
neriyan nadasen
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I have searched these forums and couldn't find a solution to my problem. Please excuse me if this question has been asked before.

I am currently experiencing a problem on on a spring web application I am developing.

I have 3 entities: Person, Team and TeamMembership, which is just a link entity to break up the ManyToMany relationship between Person and Team into two OneToMany relationships. Initially, I had the Team and TeamMembership delete working correctly whereby if I deleted or updated a Team, the TeamMemberships would be automatically deleted or updated correctly. However when I introduced the Person entity, it stopped working correctly. I get a Hibernate exception saying that the deleted object would be re-saved by cascade

I want it to work such that if I delete a Team or Person object, the corresponding TeamMemberships will be orphaned and deleted. Please assist.

Code samples as follows.

Person:


Team:


TeamMembership:


Code I execute is:


The exception is get is:
org.springframework.dao.InvalidDataAccessApiUsageException: deleted object would be re-saved by cascade (remove deleted object from associations)
 
T Mishra
Ranch Hand
Posts: 108
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if this

is called before
?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic