Sounds kinda simple, but it has proven to be a tough nut to crack...
If we have a class pojo and a student pojo, the class has a set of students and the student has a set of classes (managed by separate class_student table), and both sets in the mapping files are defined as lazy.
How do you construct the equals() method on the pojos? I'm seeing that, when I add a student to the class, the set of students must be tested in the equals() method for hib to persist the relationship. The opposite is also true for the set of classes in the student.equals() method for hib to persist the relationship.
But now I get into a circular logic issue: client tests the set for equality, which tests each student, which in turn tests the classes which tests the students which tests the classes...
Then there's the lazy issue - if I have to test the set in the equals() method, the set must be populated and the whole reason behind lazy goes right out the window.
So what is the best way to deal with this kind of thing?
|