• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

chapter 6 of JPA Pro, merging in the parent-child relationship

 
Ranch Foreman
Posts: 1922
13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:


Any comments?
Merging_detached_entities.JPG
[Thumbnail for Merging_detached_entities.JPG]
Diagram from the book about merging department and address
 
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
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic