2
I have the entity Fatura
who has a relationship OneToMany
with the entity Item
.
When I try to delete an Invoice I have the following error:
Caused by: com.mysql.jdbc.exceptions.jdbc4.Mysqlintegrityconstraintviolationexception: Cannot delete or update a Parent Row: a Foreign key Constraint fails (
bd_afunopi
.item
, CONSTRAINTFK_26i46vxf33rt1kv9wrwl42t5d
FOREIGN KEY (fatura_nota
) REFERENCESfatura
(nota
))
I am setting Calendar. Type as ALL in the two entities, this way:
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 can I delete this invoice and all its items?
How’s the foreclosure coming? Take a look at this topic here: http://stackoverflow.com/questions/32146911/hibernate-throws-cannot-delete-or-update-a-parent-row-a-foreign-key-constraint Ps: Watch out for the comment explaining the remove: delete(Session.get(Employee.class, 10)); where 10 is the ID he wants to remove.
– Antonio S. Junior
@Antôniojúnior was just that, thank you. Post the answer I will mark it as correct.
– DiegoAugusto
Oops, thank you too! :)
– Antonio S. Junior