The most common cause of the problem is that you're trying to remove from data base an object that is still referenced from parent's collection (usually annotated with @OneToMany(cascade = CascadeType.ALL)). Here is a quick sample of such relation:
@Entity public class Course implements Serializable { @OneToMany(cascade = CascadeType.ALL, mappedBy = "course") private ListWhen you know what's causing the problem fixing it is very simple. You need to remove an object from parent's collection before deleting it in database:classes; .... } @Entity public class Clazz implements Serializable { @ManyToOne @JoinColumn(name = "COURSE_ID") private Course course; ... }
course.getClasses().remove(clazz); entityManager.remove(clazz);
No comments:
Post a Comment