This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "how cascade delete works?" Watch "how cascade delete works?" New topic
Author

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,
Prashant


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

Joined: Feb 13, 2004
Posts: 19
Hi,

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
objects.
========================================================================

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 ��
 
wood burning stoves
 
subject: how cascade delete works?
 
Similar Threads
Cascade-delete Question
When is "DirectorId" column populated for new movie record?
Cascade-delete & multiplicity
hibernate:many-to-many: hibernate deletes too much
CMR configuration confusion