Hi, in chapter 6 of JPA Pro, Merging with detached entities section:
Note that we did not cascade the merge operation to the Department entity. We generally cascade operations only down from parent to child,
not upward from child to parent. Doing so is not harmful, but it requires more effort from the persistence provider to search out changes. If the Department entity
changes as well, it is better to cascade the merge from the Department to its associated Employee instance....
This code does not cascade Merge to the Department entity because Department is the parent and Employee is the child.
I guess a child means the table with a foreign key referring to another table, which is the parent. In this case Employee is the child because it has a foreign key referring to the department id.
I think the child is the owner of the one-to-one or many-to-one relationship while the parent is the being owned side.
But this code cascades Merge to the Address entity. Address is the parent and the Employee is the child, same as the parent-child relationship of Department and Employee.
Why do we need to put cascadeType.Merge for the address while the cascade type is not present for the department ?
Or, we can code in this way:
Happily living in the valley of the dried frogs with a few tiny ads.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop