title: Saving entity with one-to-many relationship
body: <p>I think I have a bad setup for my hibernate database. I have <code>Citizen</code> entities who have one to many relationships with <code>WeeklyCare</code> entities. Below is the relevant code.</p>
  
  <p>Citizen:</p>
  
  <pre><code>@Entity
  @Table(name = "citizens")
  public class Citizen {
  @Id
  @Size(max = 10, min = 10, message = "CPR must be exactly 10 characters")
  private String cpr;
  
  @OneToMany()
  @JoinColumn(name = "cpr")
  private List&lt;WeeklyCare&gt; weeklyCare;
  }
  </code></pre>
  
  <p>WeeklyCare:</p>
  
  <pre><code>@Entity
  public class WeeklyCare {
  @EmbeddedId
  private WeeklyCareIdentifier weeklyCareIdentifier;
  }
  </code></pre>
  
  <p>WeeklyCareIdentifier:</p>
  
  <pre><code>@Embeddable
  public class WeeklyCareIdentifier implements Serializable {
  
  @NotNull
  @Size(max = 10, min = 10, message = "CPR must tbe exactly 10 characters")
  private String cpr;
  
  @NotNull
  private Integer week;
  
  @NotNull
  private Integer year;
  }
  </code></pre>
  
  <p>I have some problems when I want to save data to the database:</p>
  
  <ol>
  <li>I can't save <code>WeeklyCare</code> first, because it requires a <code>Citizen</code>. </li>
  <li>When I send the citizens to my backend, the objects contain a list of <code>WeeklyCare</code>. When I try to save the citizens, it gives me this error: <code>Unable to find Application.Models.WeeklyCare with id Application.Models.WeeklyCareIdentifier@b23ef67b</code></li>
  </ol>
  
  <p>I can solve the problem by clearing the list of <code>WeeklyCare</code> on the <code>Citizen</code> before saving it, and then saving the list of <code>WeeklyCare</code> after, but that feels like a terrible way to do it.</p>
  
  <p>I guess I want hibernate to ignore the list of <code>WeeklyCare</code> when it saves a <code>Citizen</code>, but acknowledge it when it fetches a <code>Citizen</code>. Is this possible? Or is there an even better way to do it? Thanks.</p>