title: Updating an entity, but without creating new records for @onetomany relationship is already exists in db table
body: <p>I am searching for an answer for almost all day and couldnt figure out how to solve this. So that's why Im asking, please advise.</p>
  <p>I got 2 entities, Patient and Dietician - both of them, stored in one table called users - I have parent entity called User and Patient/Dietician inherits from it.</p>
  <p>What I want to do, I have a view on which Patient can update information about himself (he has to say, what age he is, height, weight, what type of diet he wants and he can choose dietician from the dropdown list (those dieticians already exists in database table) What I want to do now is that I want save Patient with those informations, but every time i do save it is saving those informations but also creating new dietician entry (duplicating it) or stating that he cannot create that dietician because emailaddress field is unique (that's how I wanted). Why every time I do save it is creating a new entry for ManyToOne relationship? Why this can't use existing Dietician, and just set FK (dietician_id) with id of existing dietician.</p>
  <p>Here is bunch of code</p>
  <pre><code>@Entity
  @DiscriminatorValue(&quot;1&quot;)
  public class Patient extends User {
          
     private Double weight;
          
     private Double height;
          
     private Integer age;
          
     @Enumerated(value = EnumType.STRING)
     private DietType dietType;
          
     @Enumerated(value = EnumType.STRING)
     private Gender gender;
          
     @Enumerated(value = EnumType.STRING)
     private PsychicalActivity psychicalActivity;
          
     @OneToMany(mappedBy = &quot;patient&quot;, cascade = CascadeType.ALL)
     private List&lt;Diet&gt; diets;
          
     @ManyToOne(cascade = CascadeType.ALL)
     private Dietician dietician;
          
     @OneToMany(mappedBy = &quot;patient&quot;, cascade = CascadeType.ALL)
     private List&lt;Visit&gt; visits;  
  </code></pre>
  <pre><code>@Entity
  @DiscriminatorValue(&quot;2&quot;)
  public class Dietician extends User {
          
      @OneToMany(mappedBy = &quot;dietician&quot;, cascade = CascadeType.ALL)
      private Set&lt;Patient&gt; patients;
          
      @OneToMany(mappedBy = &quot;dietician&quot;, cascade = CascadeType.ALL)
      private Set&lt;Visit&gt; visits;
          
      public Dietician() {}
          
      public Dietician(String firstName, String lastName, String emailAddress, String password, Set&lt;Role&gt; roles) {
          super(firstName, lastName, emailAddress, password, roles);
      }
  </code></pre>
  <pre><code>@PostMapping(&quot;/update-data&quot;)
  public String sendUpdateForm(@ModelAttribute Patient patientForm){
      patientService.setUserData(patientForm);
      return &quot;patientHomePage&quot;;
  }
  </code></pre>
  <pre><code>@Override
  public Patient setUserData(Patient patientForm) {
      Patient patient = patientRepository.findByEmailAddress(patientForm.getEmailAddress());
      patient.setGender(patientForm.getGender());
      patient.setPsychicalActivity(patientForm.getPsychicalActivity());
      patient.setAge(patientForm.getAge());
      patient.setDietician(patientForm.getDietician());
      
      return patientRepository.save(patient);
      }
  </code></pre>