我正在尝试删除使用jackrabbit保存的节点,但我收到此错误。
Failed to delete file
! javax.jcr.nodetype.ConstraintViolationException: Unable to perform operation. Node is protected.
以下是我用来保存它的代码:
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
Node parent = (Node) itemAtPath(parentPath, session);
Node newNode = parent.addNode(nodeName);
newNode.addMixin("mix:versionable");
session.save(); // Create Root Node
VersionableChanges changes = new VersionableChanges(newNode.getSession());
changes.checkout(newNode);
Binary binary = session.getValueFactory().createBinary(in);
newNode.setProperty(PROPERTY_DATA, binary);
newNode.setProperty(PROPERTY_NAME, fileName + System.currentTimeMillis());
newNode.setProperty(PROPERTY_CREATEDBY, createdBy);
newNode.setProperty(PROPERTY_CREATEDDATE, createdDate);
newNode.setProperty(PROPERTY_COMMENT, comment);
Value value = session.getValueFactory().createValue(binary);
changes.checkin();
session.save();
以下是我用来删除它的代码:
session = repository.login(new SimpleCredentials("admin", "admin".toCharArray()));
Version fileVersion = null;
Node fileNode = null;
if (version != null && !version.isEmpty()) {
fileVersion = session.getWorkspace().getVersionManager().getVersionHistory(path).getVersion(version);
} else {
fileVersion = session.getWorkspace().getVersionManager().getBaseVersion(path);
}
fileNode = fileVersion.getFrozenNode();
fileNode.remove();
//need to save session to persist the remove operation
session.save();
如何克服此错误?
答案 0 :(得分:2)
冻结节点受到保护,因为删除它们(可能)会使版本存储处于损坏状态。为了删除"完成"从历史版本来看,你必须这样:
VersionHistory history = session.getWorkspace().getVersionManager()
.getVersionHistory(info.getVersionedNodePath());
history.removeVersion(info.getVersionName());
session.save();