I am working with JBOSS, SEAM und EBJ 3.0 and I am Hibernate Annotations.
I have a ManyToMany relationship between 2 beans and want to delete instances of both Beans. Here the code :
Bean1
Code:
@ManyToMany(targetEntity = User.class,fetch = FetchType.EAGER)
@JoinTable(name = "CFP_userprofile_contributable_map", joinColumns = @JoinColumn(name = "c_id"), inverseJoinColumns = @JoinColumn(name = "login"))
public Collection<User> getFavoriteUsers() {
return favoriteUsers;
}
Bean2
Code:
@ManyToMany(mappedBy = "favoriteUsers",targetEntity = Contributable.class, fetch = FetchType.EAGER)
public Collection<Contributable> getContributableFavorites() {
if (contributableFavorites == null) {
contributableFavorites = new ArrayList<Contributable>();
}
return contributableFavorites;
}
When I delete an instance of bean1 with
Code:
entitymanager.remove(bean1);
this works, but when I try to delete an instance of bean2 I get this exception:
Code:
23:12:58,859 ERROR [JDBCExceptionReporter] Cannot delete or update a parent row: a foreign key constraint fails (`jbossdb/cfp_contributable`, CONSTRAINT `FKCE4305C0FFE09684` FOREIGN KEY (`creator_login`) REFERENCES `cfp_user` (`login`))
23:12:58,859 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
How can I use the ManyToMany relationship and delete instances of both beans?