Here's the code. Essentially I have two lists, one from the persisted object, and one containing "new" values contained in the pageNo array. All of my operations are performed directly on the object returned by Hibernate.
Code:
session = HibernateSessionFactory.getSessionFactory().openSession(ConnectionProperties.getConn("iwsdb"));
newGroup = (Group) session.load(Group.class, groupNo);
oldList = newGroup.getGroupPages();
for(int i=0;i<pageNo.length;i++) {
page_no = new Long(pageNo[i]);
page = (Page) session.load(Page.class, page_no);
newPageList.add(page);
}
List tempOldList = new ArrayList(oldPageList);
for(int i=0;i<tempOldList.size();i++) {
page = (Page) tempOldList.get(i);
if(newPageList.contains(page)) {
newPageList.remove(page);
} else {
newGroup.getGroupPages().remove(page);
}
}
for(int i=0;i<newPageList.size();i++) {
page = (Page) newPageList.get(i);
newGroup.getGroupPages().add(page);
}
session.saveOrUpdate(newGroup);
session.flush();
[/code]