wutzebaer
wutzebaer

Reputation: 14875

JCR Jackrabbit Versionising

Hi iam trying to restore a version of a node. But something goes wrong:

    Session session = repository.login(new SimpleCredentials("test1", "".toCharArray()));

    Workspace ws = session.getWorkspace();

    Node parentNode = session.getRootNode();

    //Create a first version
    Node n = parentNode.addNode("childNode", "nt:unstructured");
    n.addMixin("mix:versionable");
    n.setProperty("anyProperty", "Blah");
    session.save();
    Version firstVersion = ws.getVersionManager().checkin("/childNode");

    // add new version
    ws.getVersionManager().checkout("/childNode");
    n.setProperty("anyProperty", "Blah2");
    session.save();
    ws.getVersionManager().checkin("/childNode");


    // restoring old version
    ws.getVersionManager().restore("/childNode", firstVersion, true);

After that i get

javax.jcr.version.VersionException: VersionManager.restore(String, Version, boolean) not allowed on existing nodes; use VersionManager.restore(Version, boolean) instead: /childNode

Upvotes: 2

Views: 2379

Answers (1)

Jeroen
Jeroen

Reputation: 3146

The problem is in the restore method call. If you look at the API docs you will see that the path (first argument) should not point to an existing node. If it does you will get this exception. Try with /childNode2 and it should restore it to that location.

From what it looks like:

ws.getVersionManager().restore(firstVersion, true);

should work and restore the previous version to the current location.

Upvotes: 2

Related Questions