我正在尝试将带有子节点的Node移动到JCR存储库中的另一个节点,但我一直收到此错误:
在工作空间“default”中找不到节点“/ A / B [2]”的节点定义,允许使用相同名称的兄弟节点。
如果我理解正确,它会试图告诉我,我正在尝试在目标路径中创建一个具有已存在的ID的节点。但事实并非如此!
我的结构由两个父母组成,每个父母都有一个孩子:
A - >乙
C - > d
我正在尝试将D移动到B,因此之后的结构将是:
A - > B - > d
C
这是我的代码,我希望路径设置正确:
private void moveNode(final Node movedNode, final Node destinationNode)
throws RepositoryException {
System.out.println(movedNode.getPath()); // prints "/C/D"
System.out.println(destinationNode.getPath()); // prints "/A/B"
modeshape.execute(new JcrHandler<Object>() {
@Override
public Object execute(Session session) throws RepositoryException {
session.move(movedNode.getPath(), destinationNode.getPath());
return null;
}
});
}
感谢您的建议!
答案 0 :(得分:3)
当然道路不正确!愚蠢的我!
更改路径可以解决问题:
session.move(movedNode.getPath(), destinationNode.getPath()+"/"+movedNode.getName());
我需要更仔细地阅读文档:
提供的destAbsPath不得在其最终元素上有索引。如果是,则立即抛出RepositoryException。严格地说,destAbsPath参数实际上是新位置的父节点的绝对路径,附加了移动节点所需的新名称。
来源:http://www.day.com/specs/jcr/1.0/7.1.7_Moving_and_Copying.html