What is cascade in Hibernate?
Friday, February 26, 2010
Cascade specifies which operations should be casecaded from the parent object to the associated object. These values can be applied for association specified in the hbm files.
The meaningfull values are;
1) cascade="none" the default, tells Hibernate to ignore the association.
2) cascade="save-update" cascades save and update actions from the parent to the child. In other words it tells Hibernate to navigate the association when the transaction is committed and when an object is passed to save() or update() and save newly instantiated transient instances and persist changes to detached instances.
3) cascade="delete" cascades the delete action from the parent to the child or tells Hibernate to navigate the association and delete persistent instances when an object is passed to delete().
4) cascade="all" means to all actions are cascaded from the parent to the child. Cascade both save-update and delete, as well as calls to evict and lock.
5) cascade="all-delete-orphan" means the same as cascade="all" but, in addition, Hibernate deletes any persistent entity instance that has been removed (dereferenced) from the association (for example, from a collection). All actions are cascaded from the parent to the child, orphan children are deleted.
6) cascade="delete-orphan" Hibernate will delete any persistent entity instance that has been removed (dereferenced) from the association (for example, from a collection).
Leave your comment here ...
Labels:
Hibernate