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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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: 6
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: 107

What happens if this

is called before
?


Thanks,
Tushar (SCJP 1.5)
 
 
subject: Hibernate error when deleting child objects when parent object is deleted
 
Similar Threads
Entity object not getting persisted: new object was found through a relationship that was not marked
Bi-directional many-to-many mapping question
deleting causes : not-null property references a null or transient value
what us mean mappedBy="item" ?
JPA: Cascade delete for join tables with composite key