4 Replies Latest reply on Mar 9, 2013 10:23 AM by jonathandfields

    PathNotFoundException during Workspace.clone()

    jonathandfields

      Am I doing something wrong, or should this work:

      @Singleton
      @Startup
      public class CloneTest  {
           @PostConstruct
           public void start() {
                try {
                     Context context = new InitialContext();
                     Repository repository = (Repository) context.lookup("java:/jcr/sample");
                     Session session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
                     Node rootNode = session.getRootNode();
                     Node a = rootNode.addNode("a");
                     a.addMixin(NodeType.MIX_SHAREABLE);
                     Workspace ws = session.getWorkspace();
                     ws.clone(ws.getName(), a.getPath(), "/b", true);
                     session.save();
      
                } catch(Exception e) {
                     e.printStackTrace();
                }
                
           }
      }
      

      It is throwing:

      12:15:28,459 ERROR [stderr] (MSC service thread 1-12) javax.jcr.PathNotFoundException: No node exists at path '/a' in workspace "default"
      12:15:28,460 ERROR [stderr] (MSC service thread 1-12)      at org.modeshape.jcr.JcrSession.cachedNode(JcrSession.java:526)
      12:15:28,461 ERROR [stderr] (MSC service thread 1-12)      at org.modeshape.jcr.JcrSession.node(JcrSession.java:547)
      12:15:28,461 ERROR [stderr] (MSC service thread 1-12)      at org.modeshape.jcr.JcrSession.node(JcrSession.java:566)
      12:15:28,461 ERROR [stderr] (MSC service thread 1-12)      at org.modeshape.jcr.JcrSession.move(JcrSession.java:898)
      12:15:28,462 ERROR [stderr] (MSC service thread 1-12)      at org.modeshape.jcr.JcrWorkspace.move(JcrWorkspace.java:427)
      12:15:28,462 ERROR [stderr] (MSC service thread 1-12)      at org.modeshape.jcr.JcrWorkspace.clone(JcrWorkspace.java:258)
      ...
      

       

      This is with Modeshape .3.1.2 and JBoss AS 7.1, within an EJB with CMT.

       

      I tried adding a session.save() after creating node "a" but got the same results.

       

      If it is a bug please let me know and I will submit to JIRA.

        • 1. Re: PathNotFoundException during Workspace.clone()
          rhauch

          "Workspace.clone" is a workspace-write method, which means it works only against the persisted state and immediately performs the operation and persists it. Therefore, it cannot see transient state within sessions. See Section 10.1.5.2 in the JSR-283 specification for a list of all workspace-write methods.

           

          Simple move the "session.save()" before the "ws.clone(...)" call.

           

          BTW, even moving the "session.save()" before the "ws.clone(...)" call probably doesn't work in 3.1.3.Final or earlier within a single CMT (or any user transaction) because of MODE-1822, which has been fixed in 'master' and will be available in 3.2.

          • 2. Re: PathNotFoundException during Workspace.clone()
            jonathandfields

            Thanks, I verified if /a already exists the clone() succeeds, but if it is created in the same session it fails (even with the save() before the clone() since I'm running 3.1.2). Will be looking forward to the fix in 3.2. In the mean time, I'll see if separate BMT transactions can be used as a workaround.

            • 3. Re: PathNotFoundException during Workspace.clone()
              rhauch

              I don't think BMT will work, either. MODE-1822 covered all external transactions.

              • 4. Re: PathNotFoundException during Workspace.clone()
                jonathandfields

                Thanks. I will wait to use shared nodes until 3.2.

                 

                I am just starting to investigate their use and am wondering if there are any best practices or rules of thumb?  For example, I am tracking digital video files, so I have a  node containing information about the file. The video information node can logically appear in multiple paths -  in a heirarchy organized by title, date, genre, etc. They may also appear in a user's "my videos" folder. Is this a "good" use of shared nodes - it seems to be what they were intended for.  So far I have been using references, but I'm starting to end up with circular reference paths so I am thinking that shared nodes may be a better design.