Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/Group.java =================================================================== diff -u -rf05e48f6f771c7d2f898aa3a95f3098494f141b2 -r01349ae55aa04376236920a2314eda93d93d5f6d --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/Group.java (.../Group.java) (revision f05e48f6f771c7d2f898aa3a95f3098494f141b2) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/Group.java (.../Group.java) (revision 01349ae55aa04376236920a2314eda93d93d5f6d) @@ -374,18 +374,12 @@ return entry; } - /** Remove the branch with which this group is associated. + /** + * Remove the branch with which this group is associated. + * Actually calls the SequenceActivity to do the removal as it is the SequenceActivity that has the hibernate cascade. + * So its the activity that must be saved, not the group. Method left here to make it easier to find. */ public void removeGroupFromBranch(SequenceActivity branch) { - if ( getBranchActivities() != null ) { - Iterator iter = getBranchActivities().iterator(); - while (iter.hasNext()) { - BranchActivityEntry object = (BranchActivityEntry) iter.next(); - if ( object.getBranchSequenceActivity().equals(branch) ) { - iter.remove(); - } - } - } - // branch.getGroupsForBranch().remove(this); + branch.removeGroupFromBranch(this); } } Index: lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java =================================================================== diff -u -rcbb6dc551eb67fef11ac75737d475fb00dcae138 -r01349ae55aa04376236920a2314eda93d93d5f6d --- lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java (.../SequenceActivity.java) (revision cbb6dc551eb67fef11ac75737d475fb00dcae138) +++ lams_common/src/java/org/lamsfoundation/lams/learningdesign/SequenceActivity.java (.../SequenceActivity.java) (revision 01349ae55aa04376236920a2314eda93d93d5f6d) @@ -260,5 +260,21 @@ return listOfValidationErrors; } + /** + * Remove the entry mapping the given group to this branch. + * Need to remove it from the branch end, as it is the branch end that + * has the all-delete-orphan cascade (LDEV-1766) + */ + public void removeGroupFromBranch(Group group) { + if ( getBranchEntries() != null ) { + Iterator iter = getBranchEntries().iterator(); + while (iter.hasNext()) { + BranchActivityEntry object = (BranchActivityEntry) iter.next(); + if ( object.getGroup().equals(group) ) { + iter.remove(); + } + } + } + } }