java - 使用 modeshape 在 JCR 存储库中递归移动节点

标签 java repository nodes jcr modeshape

我试图将一个节点及其子节点移动到 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/

相关文章:

javascript - 为什么我无法通过 document.getElementById ("node' s_id").child 选择子节点?

java - BiFunction 接口(interface)中的默认 andThen() 方法

java - 服务器模拟器的设计模式

java - 从 Spring Boot 执行 Neo4j 密码查询

repository - libs-snapshot 和 libs-snapshot-local 之间的区别?

python - 递归节点

sql-server - 在不知道节点名称的情况下查询 XML 创建字段名称

java - 是否可以在pom中定义javacpp-preset的环境?

java - 给定一个句子,单词之间有多个空格。删除多余的空格,使句子中的单词之间只有一个空格

maven - 在 Clojure 中需要具有本地 Maven 存储库的 Java 类和命名空间组织