title: How to properly map hierarchical JPA entities to a dto model (to save and update via rest)
body: <p>I have an 2 level entity hierarchy (Post and PostComments; one OneToMany relation) and implemented it <a href="https://vladmihalcea.com/jpa-hibernate-synchronize-bidirectional-entity-associations/" rel="nofollow noreferrer">this suggested way</a> (in short: owner is the many side, and there are dedicate methods on one-side to add and remove sub entities).</p>
  
  <p>While this is working fine i am struggling at map this in a proper DTO (to be json-ed). I don't want to expose the entities directly.
   Proper means especially that i can do 
  json->mapToEntity->repository.save(entity) </p>
  
  <p>This should then update all Post fields but also all PostComment fields (add remove as needed).</p>
  
  <p>The only way i see at the moment is to completely reconstruct the entity on update: Retrieve the entity to be updated and set all fields as given by json, then save.</p>
  
  <p>Is there a better way to update such an entity structure via json model (rest api)</p>