1:M relationship - How do I remove & add the new ones
Posted on 2004-03-26
I have a table which has a
Unit : Unit-Teaches : INSTRUCTOR
1 : M : 1
Unit-Teaches hold the unit_key (UNit table) & instructor_key(Instructor Table)
A Unit can have one to many instructor. So the user when they update the unit can change all the instructor , add one/many or delete one/many.. My question how do I do this in a CMP and CMR? Should I be deleting all the record in the UNit-Teaches and then add again from the list I get from the user. Or how would I loop from the ones already existing and the ones I want to add or delete?
//get the collection of Instructor already associated to this unit.
Collection col = ul.getCrse_unit_instructor_teaches_fk_unit_key();
Iterator it = col.iterator();
Crse_unit_instructor_teachesLocal uitl = (Crse_unit_instructor_teachesLocal) it.next();
Long instKey = uitl.getInstr_instructor_fk_instructor_key().getInstructor_key();
//Loop through the instructor list selected by the user.
for(int i=0; i < unit.getUnitInstructorList().length; i++)
//get the instructor key
Long instructorKey = unit.getUnitInstructorList()[i];
Any help would be appreciated