File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate error when deleting child objects when parent object is deleted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate error when deleting child objects when parent object is deleted" Watch "Hibernate error when deleting child objects when parent object is deleted" New topic
Author

Hibernate error when deleting child objects when parent object is deleted

neriyan nadasen
Greenhorn

Joined: Feb 21, 2012
Posts: 7
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

Joined: Apr 04, 2006
Posts: 108

What happens if this

is called before
?


Thanks,
Tushar (SCJP 1.5)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate error when deleting child objects when parent object is deleted