【问题标题】:Recursive moving of Nodes in a JCR repository with modeshape使用 modeshape 在 JCR 存储库中递归移动节点
【发布时间】:2013-10-30 16:10:02
【问题描述】:

我正在尝试将一个节点及其子节点移动到 JCR 存储库中的另一个节点,但我不断收到此错误:

在工作区“default”中找不到节点“/A/B[2]”允许同名同级的节点定义。

如果我理解正确,它试图告诉我我正在尝试在目标路径中创建一个节点,其 ID 已经存在于那里。但事实并非如此!

我的结构由两个父母组成,每个父母都有一个孩子:

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;
            }

        });
}

感谢您的建议!

【问题讨论】:

    标签: java repository nodes jcr modeshape


    【解决方案1】:

    当然路径不正确!骗我!

    改变路径解决了这个问题:

    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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-23
      • 2011-11-04
      • 2016-10-31
      • 1970-01-01
      • 2017-05-07
      相关资源
      最近更新 更多