title: Converting dto to entity saving strategy in jpa
body: <p>In a spring boot application with spring data-jpa we use hibernate implementation</p>
  
  <p>when we have a Parent entity with a list of Child (one to many and cascade.all) and we use dto what is the strategy to saving?</p>
  
  <p>We must loop on the child, compare with dto, if there are existing element, update value, if they are some new, add element, if some has been removed, remove it from the list?</p>
  
  <p>Example</p>
  
  <pre><code>Parent parent = repo.findById(Integer id);
  
  //remove items who dont exit anymore
  Childs childs = bean.getChild();
  for (Iterator&lt;Childs&gt; iterator = childs.iterator(); iterator.hasNext();) {
  
      //compare with dto...
  
  }
  
  
  for (ChildsDto childsDto : ChildsDto) {
  
      if(childsDto==null){
          //add new element in the list of childs of parent
      }else{
          update element in the list of childs of parent
      }
  
  }
  </code></pre>