The issue is that CascadeType.DELETE
which is implied by CascadeType.ALL
in your code above applies to the objects in the EntityManager, but not necessarily the database. Configure JPA to generate a ddl file. Take a look at the ddl
file, you'll notice that ON DELETE CASCADE
is not added to the constraint. Add ON DELETE CASCADE
to actual SQL in the ddl
file, then update your database schema from the ddl. This will fix your problem .
This link shows how to use ON DELETE CASCADE
on for CONSTRAINT
in MySQL. You do this on the constraint. You can also do it in a CREATE TABLE
or ALTER TABLE
statement. It's likely that JPA creates the constraint in an ALTER TABLE
statement. Simply add ON DELETE CASCADE
to that statement.
Note that some JPA implementors do provide a means for this functionality, thus use at your own risk.