I use @Version for Student that has a list of courses that do not have @Version.
@Entity
Class Student {
....
List<Course> getCourses();
@Version
public Integer getVersion() {
}
}
@Entity
Class Course {
}
When I added a course to a student, then increase the student's version without reloading the student from database to match the version in database.
The Student has other lazy property, so at some point I used
session.lock(student, LockMode.NONE);
to connect the detached entity to session in order to fetch lazy properties.
But I got exception:
"entity has dirty collection"
How Lock works? How does Hibernate know dirty collection? In term of version, they match version in persistence.
Thanks for help.
|