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 to organize deleting all child rows when parent row will deleted? I'm tried to set CascadeType.DELETE_ORPHAN for Accounts table, but with that I can't to delete parent rows if childs is exists.
show create table
MySQL output for both tables? – Marcell Fülöp 11 hours agoON 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. – Marcell Fülöp 11 hours ago