我试图将一个节点及其子节点移动到 JCR 存储库中的另一个节点,但我不断收到此错误:
A node definition that allows same name siblings could not be found for the node "/A/B[2]" in workspace "default".
如果我理解正确的话,它试图告诉我,我正在尝试在目标路径中创建一个节点,其 ID 已经存在于那里。但事实并非如此!
我的结构由两个 parent 组成,每个 parent 有一个 child :
A --> B
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;
}
});
}
感谢您的建议!
最佳答案
当然路径不正确!我真是个傻子!
更改路径解决了问题:
session.move(movedNode.getPath(), destinationNode.getPath()+"/"+movedNode.getName());
我需要更仔细地阅读文档:
The destAbsPath provided must not have an index on its final element. If it does then a RepositoryException is thrown immediately. Strictly speaking, the destAbsPath parameter is actually an absolute path to the parent node of the new location, appended with the new name desired for the moved node.
来源:http://www.day.com/specs/jcr/1.0/7.1.7_Moving_and_Copying.html
关于java - 使用 modeshape 在 JCR 存储库中递归移动节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19676498/