ERROR: update or delete on table "tablename" violates foreign key constraint : <p>I'm trying to delete the parent student or parent course and I get this error: </p>

<p><strong>Caused by: org.postgresql.util.PSQLException: ERROR: update or delete on table "student" violates foreign key constraint "fkeyvuofq5vwdylcf78jar3mxol" on table "registration"</strong></p>

<p>RegistrationId class is a composite key used in Registration class. I'm using Spring data jpa and spring boot.</p>

<p>What am I doing wrong? I know that putting cascadetype.all should also remove the children when the parent is deleted but it is giving me an error instead.</p>

<pre><code>@Embeddable
public class RegistrationId implements Serializable {

  @JsonIgnoreProperties("notifications")
  @OneToOne(cascade=CascadeType.ALL)
  @JoinColumn(name = "student_pcn", referencedColumnName="pcn")
  private Student student;

  @JsonIgnoreProperties({"teachers", "states", "reviews"})
  @OneToOne(cascade=CascadeType.ALL)
  @JoinColumn(name = "course_code", referencedColumnName="code")
  private Course course;
</code></pre>

<p><br>Registration class</p>

<pre><code>@Entity(name = "Registration")
@Table(name = "registration")
public class Registration {

@EmbeddedId
private RegistrationId id;
</code></pre>
