title: Using cascading from child to parent objects using JPA
body: <p>I have the following scenario.</p>
  
  <p>We have two objects in our domain which form a parent and child relationship. </p>
  
  <p>Person is the parent and Role is the child. These two objects extend from the same ancestor. </p>
  
  <p>Instead of modelling the relationship as bi directional the child contains only the object Id of the parent represented as a long.</p>
  
  <p>The parent has a @oneToMany mapping to the child.</p>
  
  <p>The issue we are experiencing is as follows: The domain layer currently creates and persists the child in isolation and then simply updates the id of the parent onto itself.</p>
  
  <p>The problem with this approach however is that the Person that is already loaded into the Persistent Context, does not get refeshed with this new Role. This approach is causing havoc in our application  as we attempt to orchastrate several operations within a single transaction. We can't leverage 2nd level caching either. We are looking to create a bidirectional relationship, however I am unclear as to what the best approach to dealing with the child object is.</p>
  
  <p>All the suggestions I have seen indicate that the Parent object should be saved and this should then cascade to the child. It is also suggested that this approach should be followed for all cascading types. So a change to the child is persisted is via the parent.</p>
  
  <p>I'm not disputing this approach however, seeing as there is already an implementation, is it viable to have  cascading from the child to the parent? I would imagine that this should be applicable to Merge and Refresh? This seems a viable approach for synchronizing the persistent context with the changes to the object, without needing to change the underlying implementation, beyond adding the @ManyToOne annotations.</p>
  
  <p>I would welcome any comment or recommendations.</p>