Friday, May 15, 2015

A quick look at cascade styles in Hibernate ORM framework. By default there is no cascading of state between one associated entity and another. Hibernate does not implement persistence by reachability by default. If we want a cascade style along an association, we must specify it expicitly in the mapping file. Cascading options  can be described as persist, delete, lock. These can be combined. The associations can be parent child for these to work in that what affects the parents cascades to the child.
The cascading operations for a parent child relationship are as follows
If the parent is passed to persist, all children are passed to persist
If the parent is passed to merge, all children are passed to merge.
If the parent is passed to save, update, saveorUpdate, all the children are passed to the same
If a transient or detached child becomes referenced by a persistent parent, saveorUpdate is called.
If a parent is passed to delete, all the children are passed to delete.
If a child becomes dereferenced from a persistent parent, nothing special happens. Cascade = delete-orphan could handle this case.

No comments:

Post a Comment