I have the entity Fatura
that has a OneToMany
relationship with the entity Item
.
When I try to delete an Invoice I get the following error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Can not delete or update parent row: a foreign key constraint fails (% with% of%, CONSTRAINT% with% FOREIGN KEY (
bd_afunopi
) REFERENCESitem
(FK_26i46vxf33rt1kv9wrwl42t5d
))
I'm setting cascade.Type as ALL in the two entities, like this:
Invoice :
@OneToMany(fetch = FetchType.EAGER, mappedBy = "fatura", cascade = CascadeType.ALL)
private List<Item> items = new ArrayList<Item>();
Item :
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "fatura_nota", nullable = true)
private Fatura fatura;
How do I delete this invoice and all your items?