I'd like to access the javax.jcr.version.VersionHistory of a node that has been deleted to read metadata and change labels, or possibly restore it. How can I do that? The JCR VersionManager provides methods getBaseVersion(java.lang.String absPath) and getVersionHistory(java.lang.String absPath) that throw a PathNotFoundException when the node at absPath has been deleted, although the data is still around in the /jcr:system/jcr:versionStorage .

I'm using jackrabbit-oak 1.6.1, in case that's relevant. Thank you very much!

2 Answers

awd On Best Solutions

After the versioned node is deleted, revision data is still there in /jcr:system/jcr:versionStorage, if you have enough info about the node, you can search for its versions, nt:frozenNode nodes -

--jcr sql2
SELECT * FROM [nt:frozenNode] as n WHERE ISDESCENDANTNODE ([/jcr:system/jcr:versionStorage]) and n.[jcr:title] LIKE "name%"

version node can be cast to javax.jcr.version.Version;

Version version = (Version) frozenNode.getParent();

and restored using VersionManager.restore() -

VersionManager versionManager = session.getWorkspace().getVersionManager();
versionManager.restore(path, version, true);
Julian Reschke On

AFAIU, if the version-controlled node is deleted, access to its version history based on the original path isn't possible anymore.

This means that you'll have to keep track of that information before the node is deleted.