I have 2 tables.
// Accounts
@OneToMany(mappedBy="accounts", cascade=CascadeType.ALL)
@Cascade(org.hibernate.annotations.CascadeType.ALL)
private Set<Mails> mails;
// Mails
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name="user_id" , referencedColumnName="id", insertable=false, updatable=false)
private Accounts accounts;
How can I organize deleting all child rows when the parent row will be deleted? I have tried to set CascadeType.DELETE_ORPHAN
for the Accounts
table, but with that I can't delete parent rows if a child row exists.
show create table
MySQL output for both tables?ON DELETE CASCADE
in the foreign key definition which is explicitly required by the InnoDB engine on the table level to allow for automatic child deletions.