I am trying to copy node tree of a template to a node named "root" like the following:
Workspace workspace = session.getWorkspace();
workspace.copy(templatePath + "/initial/jcr:content/root", contentNode.getPath() + "/root");
Node rootNode = contentNode.getNode("root");
templatePath is the string to template. I am trying to copy "/initial/jcr:content/root" under the template path and paste it to child node named "root" under the node contentNode. I ran the code above and got javax.jcr.PathNotFoundException on the last line. When I went to CrxDe on AEM, the node tree has been copied and pasted, and the path actually exists although I got the error message. I tried to add
session.save();
After I copied. But the same error persisted although the nodes exists and have been copied.
What is causing it?
Session#saveafterWorkspace#copybecause it does not operate on a session and changes are applied immediately. ThecontentNodeyou have, however, is part of the current session so it might not be up-to-date (or it caches its list of children). IfSession#refreshdoesn’t help, just try resolving the node again. - Raphael Schweikert