Hello;
I have an Entity called Audit with a member called Materials which is a collection of Material Entities:
Code:
@ManyToMany(mappedBy="audits")
private List<Material> materials = new ArrayList<Material>();
I put the mappedBy here because I would like Material to be the owner of this relationship (I hope I am understanding this correctly).
In Material I have:
Code:
@ManyToMany(cascade={CascadeType.ALL})
private List<Audit> audits = new ArrayList<Audit>();
The table that is created is:
Code:
mysql> desc material_audit;
+--------------+---------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+---------+------+-----+---------+-------+
| materials_id | int(11) | NO | MUL | NULL | |
| audits_id | int(11) | NO | MUL | NULL | |
+--------------+---------+------+-----+---------+-------+
2 rows in set (0.01 sec)
This what I would expect. However the issue I have is I can't delete an Audit without getting a 'Cannot delete or update a parent row: a foreign key constraint fails' exception on this table.
I have been reading through the Annotations reference guide and I am still not sure how to map this so I can delete Audits and have the Materials persist but the material_audit mappings removed.
Any tips would be great.
Thanks,
Luke