javaaemjcr

Why do I get "javax.jcr.PathNotFoundException" when the path exists on AEM?


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?


Solution

  • Instead of session.save(), try adding a session.refresh() before you use contentNode again.