title: How to cascade delete when using inheritance and ManyToOne relationship with JPA
body: <p>I'm implementing a simple user managment system with spring. To achieve better model structure I use inheritance. The system is build on three classes. The <code>userdata</code> class which holds general information. The <code>parent</code> class which inherits and extends the user class and finally a <code>child</code> class which holds a parent object.</p>
  
  <p>What I'm trying to do is to get all children (who are referred to a parent) deleted by deleting the <code>parent</code> object.</p>
  
  <p>I'm already able to save/delete objects to/from my mySQL-DB over my view, so the repositories/services/controllers seem to work.</p>
  
  <p>To give you better understanding of my situation I put some code below.</p>
  
  <p>My <code>User</code> Class: </p>
  
  <pre><code>@Entity
  @Inheritance(strategy = InheritanceType.JOINED)
  public class UserData implements Persistable&lt;String&gt; {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @NotNull
  private String username;
  @NotNull
  private String password;
  @NotNull
  private String firstName;
  @NotNull
  private String lastName;
  </code></pre>
  
  <p>My <code>Parent</code> Class which inherits from User and holds a set of Child:</p>
  
  <pre><code>@Entity
  public class Parent extends UserData {
  
  private static final long serialVersionUID = 1L;
  
  private String imgName;
  @OneToMany(fetch = FetchType.EAGER)
  @ElementCollection
  private Set&lt;Child&gt; children;
  </code></pre>
  
  <p>My <code>Child</code> class which holds a Parent object</p>
  
  <pre><code>@Entity
  @Transactional
  public class Child implements Persistable&lt;Long&gt; {
  
  private static final long serialVersionUID = 1L;
  
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  private Long id;
  @NotNull
  private String firstName;
  @NotNull
  private String lastName;
  @NotNull
  private String birthday;
  @NotNull
  @ManyToOne(optional = false)
  private Parent parent1;
  </code></pre>
  
  <p>Hope anyone can tell me how I achieve <code>DELETE ON CASCADE</code> in my system.</p>