title: Bidirectionally @OneToMany mapped objects (parent & child): parent gets saved, child does not
body: <p>I have two entites mapped bidirectionally @OneToMany (I guess this is the right way to do so):</p>
  
  <pre><code>@Entity
  @Table(name="entry")
  @JsonIgnoreProperties(ignoreUnknown = true)
  public class Entry {
  
      @Id
      @GeneratedValue(strategy=GenerationType.AUTO)
      private Long id;
  
      @Column(unique=true)
      private String name;
  
      @OneToMany(mappedBy = "entry", fetch=FetchType.EAGER)
      @JsonManagedReference
  //    @JsonIdentityReference(alwaysAsId=true)
      private List&lt;Address&gt; addresses = new ArrayList&lt;&gt;();
  
      .....
  }
  
  @Entity
  @Table(name="address")
  public class Address {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Long id;
  
      @Null
      private String line1;
  
      @Null
      private String line2;
  
      @ManyToOne
      @JoinColumn(name = "entry_id")
      @JsonBackReference
      private Entry entry;
  
      ....
  
  }
  </code></pre>
  
  <p>When I debug the object (<code>Entry</code>) just before it's sent to be saved, I can see that it contains an array (<code>ArrayList</code> type) of <code>Address</code>es. However, each (at this moment, the only) element of that address list contains <code>Entry</code> as its attribute, and so on - they are infinitely nested.</p>
  
  <p>Note: In this situation <code>Entry</code> still does not have an <code>id</code> assigned. So I tried first to <code>persist(entry)</code> and then do <code>address.add(entry)</code>, and finally <code>flush()</code>. <strong>That didn't help</strong> in regards to what is said below to be the real problem.</p>
  
  <p>My questions is: Is this normal?</p>
  
  <p>I'm asking because when I save the <code>Entry</code> object, only the parent (<code>Entry</code>) record is created, and <code>Address</code> is not. I even suspected that there is no way for <code>Address</code> to be saved so I went ahead and created a repository interface for it. <strong>That didn't help either</strong>.</p>