1
votes

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?

1
"AEM", as in "Adobe Experience Cloud" (I had to google that)? - user7655213
Adobe Experience Manager - Rongeegee
No need for Session#save after Workspace#copy because it does not operate on a session and changes are applied immediately. The contentNode you have, however, is part of the current session so it might not be up-to-date (or it caches its list of children). If Session#refresh doesn’t help, just try resolving the node again. - Raphael Schweikert

1 Answers

0
votes

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