I am getting a problem when removing an item from a OneToMany list. I can add users without any problem but cannot remove them. I am basically, removing a user from the list and doing saveOrUpdate(account).
My AccountDO has a list of UserDO as follows
@OneToMany(mappedBy = "account", cascade = CascadeType.ALL)
@org.hibernate.annotations.Cascade( {
org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
public List<UserDO> getUsers() {
return users;
}
I originally found that with only the CascadeType.ALL, there was no error but with the next load the deleted user came back again! I then found a FAQ about this and added the second annotation. This however causes the exception below after removing the user from the List. Have I interpreted the docs wrong?
Caused by: java.sql.BatchUpdateException: Cannot delete or update a parent row: a foreign key constraint fails (`tenantchecker/tch_applicant_check`, CONSTRAINT `FK2028E125B7B27A4C` FOREIGN KEY (`user_id`) REFERENCES `tch_user` (`id`))
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:665)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:242)
... 49 more
What should I do to enable me to remove a User from the List correctly?
Thanks in advance,
John
|