List<Tree> newTrees = new ArrayList<Tree>();
// Removing actual trees and creating the new ones
Iterator<Tree> it = getTreesByParent(i1).iterator();
while (it.hasNext()) {
Tree tree = (Tree) it.next();
newTrees.add(new Tree(i2.getInode(), tree.getChild(), tree.getRelationType(), tree.getTreeOrder()));
deleteTree(tree);
}
it = getTreesByChild(i1).iterator();
while (it.hasNext()) {
Tree tree = (Tree) it.next();
newTrees.add(new Tree(tree.getParent(), i2.getInode(), tree.getRelationType(), tree.getTreeOrder()));
deleteTree(tree);
}
it = getTreesByParent(i2).iterator();
while (it.hasNext()) {
Tree tree = (Tree) it.next();
newTrees.add(new Tree(i1.getInode(), tree.getChild(), tree.getRelationType(), tree.getTreeOrder()));
deleteTree(tree);
}
it = getTreesByChild(i2).iterator();
while (it.hasNext()) {
Tree tree = (Tree) it.next();
newTrees.add(new Tree(tree.getParent(), i1.getInode(), tree.getRelationType(), tree.getTreeOrder()));
deleteTree(tree);
}
// Saving new trees
it = newTrees.iterator();
while (it.hasNext()) {
Tree tree = (Tree) it.next();
saveTree(tree);
}
try {
HibernateUtil.flush();
HibernateUtil.getSession().refresh(i1);