Am I correct in assuming that a cascade can cancel the effect of inverse. For example, if I specify inverse="true" in the parent mapping file (on a child collection), this implies that the child is responsible to maintaining the relationship and any update operation on the parent should not result in an update on the foreign key in the child table. However, if I specify cascade="save-update" in the parent mapping file (on a same child collection), this cancels out the inverse setting and cascades an update operation on the parent to the child table which results in an update on the foreign key in the child table.
Cascade allows you to implicitly write Java code that produces data consistency, for example, if a parent has a child, the child should be saved in the database when the parent is saved. It's easy to save the parent and forget to save the child. Cascade allows you to ensure that when the parent is saved, the child is saved as well.
With cascade="save-update", the following code
is equivalent to
Inverse allows you to explicitly write Java code that produces SQL optimization. Because relationship changes can be made from both sides of a bidirectional relationship, you want to ignore relationship changes made from one side of the bidirectional relationship so that SQL is optimized, otherwise, you’ll get redundant updates. For example, in a parent-child bidirectional relationship, all the programmer has to do in order to produce optimized SQL is:
1) make the Parent side the inverse side so that the Child side is responsible for managing the relationship
2) ensure that when the Parent's children property is changed, a corresponding change is made to the Child's parent property because relationship changes that are made on the Child side are the changes that really matter. As long both are done together, the Java object graph will be correctly saved on disk.
For example, the following code correctly saves the object graph when adding a new Child to a Parent:
The following lines will not update the parent foreign key on the child table.
The following line will update the parent foreign key on the child table.