title: JPA Hibernate, Persist 3 layers
body: <p>I'm trying to persist data 3 layers deep with JPA Hibernate.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th style="text-align: left;">Parent</th>
  <th style="text-align: left;">Child</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td style="text-align: left;">A</td>
  <td style="text-align: left;">B</td>
  </tr>
  <tr>
  <td style="text-align: left;">B</td>
  <td style="text-align: left;">C</td>
  </tr>
  <tr>
  <td style="text-align: left;">B</td>
  <td style="text-align: left;">D</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>A.Java</p>
  <pre><code>  @Id
    @Column(name = &quot;id&quot;)
    private String id;
  
    @OneToMany(mappedBy = &quot;bEntity&quot;, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    private List&lt;B&gt; b;
  </code></pre>
  <p>B.Java</p>
  <pre><code>  @Id
    @Column(name = &quot;b_id&quot;)
    private String id;
  
    @ManyToOne(fetch = FetchType.LAZY, cascade = CascadeType.ALL, optional = false)
    @JoinColumn(name = &quot;b_id&quot;, referencedColumnName = &quot;id&quot;, nullable = false, insertable = false, updatable = false)
    private D d;
  
    @OneToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = &quot;b_id&quot;, referencedColumnName = &quot;c_id&quot;)
    private C c;
  </code></pre>
  <p>C.Java</p>
  <pre><code>  @Id
    @Column(name = &quot;id&quot;)
    private String id;
  </code></pre>
  <p>Only A, B, D are getting saved and not C. Where am I going wrong</p>
  <p>Edit 1 :
  For persisting, I create a model of A and have a repository</p>
  <pre><code>@Repository
  public interface ARepository extends JpaRepository&lt;A, String&gt; {    
  }
  
  private final ARepository repository;
  A model = new A();
  repository.save(A)
  </code></pre>