Removing all versions of a node which was copied
asmierzchalski Jan 13, 2016 9:46 AMHello together,
i have following scenario:
I'm adding a node with the mixin type versionable. After that i check the node out to update a property, save the node and checkin. Now i copy the node. If i try to remove now all versions of the original node to remove the node itself i'm getting a 'javax.jcr.ReferentialIntegrityException: org.modeshape.jcr.cache.ReferentialIntegrityException'.
That's my example code:
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_FILE);
originalNode.addMixin(NodeType.MIX_VERSIONABLE);
originalNode.addMixin(NodeType.MIX_TITLE);
Node contentNode = originalNode.addNode(JcrConstants.JCR_CONTENT,
JcrConstants.NT_RESOURCE);
contentNode.setProperty(JcrConstants.JCR_DATA,
session.getValueFactory().createBinary(this.getClass().getResourceAsStream("/my-repository-config.json")));
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();
}
I am using the ModeShape version 4.5.0-Final.
My question is now, am i doing something wrong or is that a bug? In my eyes the original node shouldn't have relations to the copied node.
Greetings
Adam