title: Spring Data Jpa delete foreign key rows on delete mapping?
body: <p>Here is my first entity.</p>
  
  <pre><code>@Entity
  @Table(name = "person")
  public class Person {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;    
  
      private String firstName;
      private String lastName;
  
      // Removed other stuff for brevity
  }
  </code></pre>
  
  <p>Here is my second entity</p>
  
  <pre><code>@Entity
  @Table(name = "membership")
  public class Membership {
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private Integer id;
  
      private String membershipType;
  
      // Help here, I need another column called person_id which is what will correspond 
      // to persons or person rows from person table
  }
  </code></pre>
  
  <p>Essentially in <code>person</code> table we will have <code>n</code> people(<code>n</code> rows). While in <code>membership</code> table for each person we can have 3-4 columns(depending on their <code>membershipType</code> since each person can have multiple memberships like primary, group, individual, secondary etc, pardon the business logic). So in reality <code>membership</code> table could have more than <code>n</code> rows.</p>
  
  <p>Now I have couple of questions here</p>
  
  <ol>
  <li><p>Would this be a <code>OneToMany</code> or <code>ManyToOne</code> from <code>person -&gt; membership</code> table? I am guessing its <code>OneToMany</code> from <code>person -&gt; membership table</code>. </p></li>
  <li><p>How can I achieve this mapping in my jpa annotations and entity classes? I need this for delete operation i.e., if I delete a <code>membership row</code>, the corresponding <code>person row</code> should not get deleted. However if I delete <code>person row</code>, <code>ALL</code> corresponding <code>membership rows</code> should get deleted. How do I go about achieving this mapping and functionality? </p></li>
  </ol>