Wednesday, June 22, 2011

What is the difference between DELETE_ORPHAN and DELETE ?

Cascade DELETE means if this entity is deleted, delete the related entity or entities.

DELETE_ORPHAN means is an entity is removed from a related one-to-many collection, then not only disassociate it from the current entity, but delete it.

To give you an example, consider two entities: House and Room.

DELETE on the Room list on House means that if you delete the House then delete all it's Rooms.

DELETE_ORPHAN on the Room list on House means if you remove a Room from that collection, delete it entirely. Without it, the Room would still exist but not be attached to anything (hence "orphan").

In UML and OO modelling terms, this is basically the difference between composition and aggregation. The House->Room relationship is an example of composition. A Room is part of a House and doesn't exist independently.

An example of aggregation is, say, Class (parent) to Student (child). Delete the Class and the Student still exists (undoubtedly in other classes). Removing the Student from the Class doesn't typically mean deleting him or her.


Ref :- http://stackoverflow.com/questions/1377585/what-is-the-difference-between-delete-orphan-and-delete

No comments:

Post a Comment