Question

I'm trying to remove a version from the version history and I'm getting javax.jcr.ReferentialIntegrityException: Unable to remove version. At least once referenced.

When I try to remove all references to the version it seems like there aren't any and still does not allow me to remove the version. I am sure that this is not the root version and I'm also sure its not the first after the root.

This is my code:

    Version ver = manager.checkin(parentNodePath);

    VersionHistory versionHistory = manager.getVersionHistory(parentNodePath);
    PropertyIterator versionReverences = ver.getReferences();
    for (Property verRef = versionReverences.nextProperty(); versionReverences.hasNext();) {
        verRef.remove();
    }
    session.save();
    versionHistory.removeVersion(ver.getName());

Any help is greatly appreciated, thanks.

Was it helpful?

Solution

The checkin() call that creates your version on the first line of your example sets the jcr:baseVersion reference from the versionable node to the version you just created. The verRef.remove() statement can't remove this reference, as the jcr:baseVersion property is protected.

You need to either remove the content node or use methods like checkin() or update() to make the jcr:baseVersion reference to point to another version before you can remove this version.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top