1
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
}
The insertion of both records works and I can book a gift. I need that when excluding a gift, the associated reserves are also excluded, but even with the mapping above and with the cascade
I get the message from error saying:
Cannot delete or update a Parent Row: a Foreign key Constraint fails (
presente
.reserva
, CONSTRAINTFKkrcm39i10icgcfw703oi79tbr
FOREIGN KEY (presente_codigo
) REFERENCESpresente
(codigo
))
I know the message is due to the integrity of the bank, but the JPA
should not treat this behavior by deleting reservations before deleting the present?
What I need to change?
publish the method of exclusion of
Presente
.– Marcos Sousa