• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how cascade delete works?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ��
 
reply
    Bookmark Topic Watch Topic
  • New Topic