For an entity that has more than one collections:
For example,
Class Student {
@ManyToMany
List<Course> getCourses();
@OneToMany
List<Cat> getCats();
}
If I add a course to the student, and then em.merge(student). The following will happen: (from generated SQL)
1. delete all associations in the association table for courses, and insert all including for the new course.
2. delete all associations for Cat, and than add all. This is not necessary because I did not change cat collection.
Is this the way Hibernate does for merge? Is there a better? Ideally just insert one row into the association table for adding one course to the student.
Thanks for ideas.
|