File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes how cascade delete works? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "how cascade delete works?" Watch "how cascade delete works?" New topic

how cascade delete works?

Prashant Neginahal
Ranch Hand

Joined: Sep 14, 2002
Posts: 77
Lets take Movie and Director entities from HF book.

This has many-one relationship(from Movie to Director) and Movie bean has set cascade-delete in DD. If we take this picture on database, DirectorId will be the FK in Movie table.

My question is if i call remove method on Director entity bean, how the deletion actually works? The spec says(Page:132)
After removing the entity object from all relationships and removing its persistent representation, the Container must then cascade the removal to all entity beans with which the entity had been previously in container-managed relationships for which the cascade-delete option was specified.

Doest it mean, first Director entity will be deleted and then all its associated Movies will be deleted?But, how this is possible?Unless and until all referred Movies are deleted a particular Director bean cannot be deleted.

Need comments, pls.


Thanks, <br />Prashant<br />SCJP, SCBCD
David McDonagh

Joined: Feb 13, 2004
Posts: 19

I don't have a definitive answer but from my reading of the spec I think it means as you mention that the Directory entity bean will be deleted followed by associated Movie entity beans.
If an entity is deleted, and the cascade-delete deployment descriptor element is specified for a
related entity bean, then the removal is cascaded to cause the removal of the related entity object or

You have to remember that they are two steps performed by the container when deleting an entity bean i.e. Entity Bean relationship is removed followed by the persistent representation. The container maintains the relationships, so you have to think of it a little different then if you where writing the SQL to remove data directly.
One other thing though � it could be a container implementation on the sequences of data been removed !!! In any case the spec have outlined the outcome from calling entity bean or its accessor method after a cascade-delete.
I hope this helps ��
I agree. Here's the link:
subject: how cascade delete works?
It's not a secret anymore!