title: JpaRepository save() creating new child objects instead of updating
body: <p>I am currently converting the below JSON into two java objects using GSON. The Company object contains an Accounts object in a one-to-one relationship.</p>
  
  <p>JSON:</p>
  
  <pre><code>{
    "company_name": "ETHEREUM LTD",
    "accounts": {
      "next_made_up_to": "2018-11-30",
      "next_due": "2019-08-31"
    },
    "company_number": "11090535"
  }
  </code></pre>
  
  <p>Company Object:</p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "companies")
  public class Company {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @OneToOne(cascade=CascadeType.ALL)
      private Accounts accounts;
  
      @NotNull
      @SerializedName("company_number")
      @Column(unique = true)
      private String companyNumber;
  
      @SerializedName("company_name")
      private String companyName;
  
      public Company() {}
  
      public Company(String companyNumber) {
          this.companyNumber = companyNumber;
      }
  }
  </code></pre>
  
  <p>Accounts Object:</p>
  
  <pre><code>@Data
  @Entity
  @Table(name = "accounts")
  public class Accounts {
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Long id;
  
      @SerializedName("next_due")
      private Date nextDue;
  
      @SerializedName("next_made_up_to")
      private Date nextMadeUpTo;
  }
  </code></pre>
  
  <p>I have implemented a Spring Data JpaRepository to save these objects to my database.</p>
  
  <pre><code>public interface CompanyRepository extends JpaRepository&lt;Company, Long&gt; {
  }
  </code></pre>
  
  <p>I have a method to update all Company objects in the database with new JSON information.</p>
  
  <pre><code>@Scheduled(fixedRate = 50000)
  public void updateAllCompanies() {
      System.out.println("Starting update!");
      for(Company company : companyRepository.findAll()) {
          Long companyId = company.getId();
          Long accountsId = null;
          if(company.getAccounts() != null) {
              accountsId = company.getAccounts().getId();
          }
          company = getCompany(company.getCompanyNumber());
          company.setId(companyId);
          if(accountsId != null) {
              company.getAccounts().setId(accountsId);
          }
          companyRepository.save(company);
      }
  }
  </code></pre>
  
  <p>Unless I manually set the ids on both the parent and child object, these objects are created as new database entries rather than updating existing entries. Is there a better way of handling this than manually setting the ids in Java?</p>