title: CascadeType.ALL does not update child element
body: <p>I'm trying to add a new Employee-entity via my REST-api to the database. The Employee-entity contains a City property. This is a ManyToOne relationship. When I insert a new employee with a NEW (not existing) city it works fine. However, when I add a new employee with an existing city I get this error.</p>
  
  <pre><code>com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1000' for key 'PRIMARY'
  </code></pre>
  
  <p>My CascadeType is set to ALL. When I change it to SAVE_UPDATE it works fine when I insert a new Employee with an EXISTING city, but it does not work when I insert a new employee with a new city.</p>
  
  <p>Employee:</p>
  
  <pre><code>package be.pxl.backend.entity;
  
  import java.util.Date;
  import java.util.List;
  import javax.persistence.*;
  import javax.persistence.Entity;
  import javax.persistence.Table;
  import org.hibernate.annotations.*;
  import org.hibernate.annotations.CascadeType;
  
  @Entity
  @Table(name="Employees")
  public class Employee {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private int employee_id;
      private String username;
      private String password;
      private String salt;
      private String surName;
      private String name;
      private String street;
      @Column(name="house_nr")
      private String houseNr;
      @ManyToOne
      @Cascade (value={CascadeType.MERGE, CascadeType.PERSIST})
      private City city;
      private Date date_employment;
      private String mobile_phone;
      private String telephone_number;
      private String email;
      private String sex;
      private Boolean status;
      @OneToMany(mappedBy="employee")
      private List&lt;Login&gt; logins;
      @OneToMany(mappedBy = "employee")
      private List&lt;SensorUsage&gt; usages ;
  
      public List&lt;Login&gt; getLogins() {
          return logins;
      }
      public Boolean getStatus() {
          return status;
      }
      public int getEmployee_id() {
          return employee_id;
      }
      public String getUsername() {
          return username;
      }
      public String getPassword() {
          return password;
      }
      public String getSalt() {
          return salt;
      }
      public String getSurName() {
          return surName;
      }
      public String getName() {
          return name;
      }
      public String getStreet() {
          return street;
      }
      public String getHouseNr() {
          return houseNr;
      }
      public City getCity() {
          return city;
      }
      public Date getDate_employment() {
          return date_employment;
      }
      public String getMobile_phone() {
          return mobile_phone;
      }
      public String getTelephone_number() {
          return telephone_number;
      }
      public String getEmail() {
          return email;
      }
      public String getSex() {
          return sex;
      }
  
      public void setStatus(boolean status) { this.status = status; }
  
  }
  </code></pre>
  
  <p>City:</p>
  
  <pre><code>package be.pxl.backend.entity;
  
  import javax.persistence.*;
  import java.util.List;
  
  @Entity
  @Table(name="Cities")
  public class City {
  
      @Id
      private String postal_code;
      private String city;
      @OneToMany(mappedBy = "city")
      private List&lt;Destination&gt; destinations;
      @OneToMany(mappedBy = "city")
      private List&lt;Employee&gt; employees;
  
      public String getPostal_code() {
          return postal_code;
      }
      public String getCity() {
          return city;
      }
  
  }
  </code></pre>
  
  <p>This is where I persist:</p>
  
  <pre><code>package be.pxl.backend.repository;
  
  import java.util.List;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import org.springframework.data.jpa.repository.Query;
  import org.springframework.data.repository.query.Param;
  import org.springframework.stereotype.Repository;
  import be.pxl.backend.entity.*;
  
  @Repository
  public interface EmployeeRepository extends JpaRepository&lt;Employee, Integer&gt; {
      @Query("from Employee e where e.username = :username")
      Employee getEmployeeByUsername(@Param("username")String username);
  }
  </code></pre>
  
  <p>Help would be appreciated!</p>