Question

I'm trying to move a Node with its children to another Node in a JCR repository, but I keep getting this error:

A node definition that allows same name siblings could not be found for the node "/A/B[2]" in workspace "default".

If I understood it correctly, it's trying to tell me that I'm trying to create a Node in the destination path with an ID that allready exists over there. But it doesn't!

My structure consists of two parents, each with one child:

A --> B

C --> D

I'm trying to move D to B so the structure afterwards would be:

A --> B --> D

C

Here's my code, I hope that the paths are set correctly:

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

        });
}

Thanks for advice!

Was it helpful?

Solution

Of course the paths wern't correct! Stupid me!

Changing the paths to this solved the problem:

session.move(movedNode.getPath(), destinationNode.getPath()+"/"+movedNode.getName());

I need to read the documentation more carefully:

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.

Source: http://www.day.com/specs/jcr/1.0/7.1.7_Moving_and_Copying.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top