I have entities:
@Entity public class User { @ManyToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER) private List<Role> roles = new ArrayList<Role>();
@Entity public class Role { @ManyToMany(cascade=CascadeType.PERSIST, fetch=FetchType.EAGER) private Set<Permission> permissions = new HashSet<Permission>();
When performing a delete / delete, the following exception is thrown:
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`test`.`user_role`, CONSTRAINT `FK_USER_ROLE_roles_ID` FOREIGN KEY (`roles_ID`) REFERENCES `role` (`ID`))
There seems to be a problem with the generated join table and foreign keys.
How can this be fixed so that the role can be removed?
Edit:
Exported SQL shows this:
CREATE TABLE IF NOT EXISTS `user_role` ( `User_ID` bigint(20) NOT NULL, `roles_ID` bigint(20) NOT NULL, PRIMARY KEY (`User_ID`,`roles_ID`), KEY `FK_USER_ROLE_roles_ID` (`roles_ID`) )
source share