I have the classes Presente
and Reserva
, as below:
@Entity
public class Presente {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long codigo;
private String nome;
//getters e setter omitidos
}
@Entity
public class Reserva {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long codigo;
private String email;
@ManyToOne(cascade = CascadeType.REMOVE)
private Presente presente;
//getters e setter omitidos
}
Inserting both records works and I can book this one. I need to exclude a present, the associated reservations are also deleted, but even with the mapping above and with cascade
I get the error message saying:
Can not delete or update a parent row: a foreign key constraint fails (
presente
.reserva
, CONSTRAINTFKkrcm39i10icgcfw703oi79tbr
FOREIGN KEY (presente_codigo
) REFERENCESpresente
I know the message is due to bank integrity, but should codigo
not treat this behavior by deleting the reservations before deleting the present?
What do I need to change?