Uploaded image for project: 'ModeShape'
  1. ModeShape
  2. MODE-2560

Attempting to remove a version of a copied versionable node causes a ReferentialIntegrityException

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major Major
    • 5.0.0.Final, 4.6.0.Final
    • 4.5.0.Final
    • JCR
    • None
    • Hide
      try {
               Credentials creds = new SimpleCredentials("admin", "admin".toCharArray());
      
               Session session = repo.login(creds);
      
               String folderPath = "/uploads";
      
               VersionManager versionManager = session.getWorkspace().getVersionManager();
               // create original node
               Node node = session.getNode(folderPath);
               Node originalNode = node.addNode("originalNode", NodeType.NT_FOLDER);
               originalNode.addMixin(NodeType.MIX_VERSIONABLE);
               originalNode.addMixin(NodeType.MIX_TITLE);                        
               System.out.println("Original node added.");
               session.save();
               // update original node
               versionManager.checkout(originalNode.getPath());
               originalNode.setProperty(Property.JCR_TITLE, "originalNode");
               session.save();
               versionManager.checkin(originalNode.getPath());
               System.out.println("Original node updated.");
      
               // copy original node
               session.getWorkspace().copy(originalNode.getPath(), "/uploads/copiedNode");
               System.out.println("Node has been copied.");
      
               // delete all versions
               VersionHistory history = versionManager.getVersionHistory(originalNode.getPath());
               VersionIterator it = history.getAllVersions();
               while (it.hasNext()) {
                  Version version = it.nextVersion();
                  history.removeVersion(version.getName());
               }
               System.out.println("All versions of original node removed.");
               // delete original node
               originalNode.remove();
               System.out.println("Original node removed.");
               session.save();
      
               session.logout();
      }
      catch (Exception e) {
            e.printStackTrace();
      }
      
      Show
      try { Credentials creds = new SimpleCredentials( "admin" , "admin" .toCharArray()); Session session = repo.login(creds); String folderPath = "/uploads" ; VersionManager versionManager = session.getWorkspace().getVersionManager(); // create original node Node node = session.getNode(folderPath); Node originalNode = node.addNode( "originalNode" , NodeType.NT_FOLDER); originalNode.addMixin(NodeType.MIX_VERSIONABLE); originalNode.addMixin(NodeType.MIX_TITLE); System .out.println( "Original node added." ); session.save(); // update original node versionManager.checkout(originalNode.getPath()); originalNode.setProperty(Property.JCR_TITLE, "originalNode" ); session.save(); versionManager.checkin(originalNode.getPath()); System .out.println( "Original node updated." ); // copy original node session.getWorkspace().copy(originalNode.getPath(), "/uploads/copiedNode" ); System .out.println( "Node has been copied." ); // delete all versions VersionHistory history = versionManager.getVersionHistory(originalNode.getPath()); VersionIterator it = history.getAllVersions(); while (it.hasNext()) { Version version = it.nextVersion(); history.removeVersion(version.getName()); } System .out.println( "All versions of original node removed." ); // delete original node originalNode.remove(); System .out.println( "Original node removed." ); session.save(); session.logout(); } catch (Exception e) { e.printStackTrace(); }

      As mentioned in https://developer.jboss.org/thread/267273 there is a failure if you try to delete all versions of a node with the which has been updated and copied. The copy has a strong reference to the versions of the original node.

              hchiorean Horia Chiorean (Inactive)
              adamsmierzchalski Adam Smierzchalski (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: