Hello,
I am having inconsistent object state when using Hibernate
I have class School that have a collection of student
@ManyToMany(cascade = CascadeType.ALL)
@JoinTable(name = "LINK_SCH_STUDENT", joinColumns = @JoinColumn(name = "SCHOOL_ID"),
inverseJoinColumns = @JoinColumn(name = "STUDENT_ID"))
@LazyCollection(LazyCollectionOption.EXTRA)
private List<Students> associatedStudents;
I have a transactional method that links a student to a school:
@Transactional
LinkStudentToSchool (schoolId, StudendID){
flush();
int result = getSession().createSQLQuery("INSERT INTO " + getSchemaName()
+ ".LINK_SCH_STUDENT(SCHOOL_ID, STUDENT_ID) " +
"Values (:recipient_group_id, :contentId)")
}
I am writing integration
test for this method.
@Transactional
TestLinkStudentToSchool {
school =new School ("GeorgiaTech", ....)
schoolId = saveOrUpdate (school)
studentID = saveOrUpdate (new Student ("LazyStudent", ....))
LinkStudentToSchool (schoolId, studentID)
school.getAssociatedStudent // RETURN NULL !!!
}
Why is this happening, I already called a transactional method to add a student a school (update the link table), but the state of the collection of students
in the school did not get updated !!
Is this a caching issue ? is it because I have nested @transactional?
I will really appreciate any feedback
Thanks