Hibernate error when deleting child objects when parent object is deleted
posted 2 years ago
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.
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)