javax.jcr.nodetype.ConstraintViolationException 在新节点中找不到强制子节点 jcr:content

javax.jcr.nodetype.ConstraintViolationException Mandatory child node jcr:content not found in a new node

在AEM中使用JcrUtil.createPath在DAM Asset中创建文件夹(目录)时,抛出异常,错误为OakConstraint0025: /content/dam/upload/Type/99/MBT/front[[nt:file]] : 在新节点 中未找到强制子节点jcr:content。这可能意味着子 jcr:content 节点需要与目录同时创建。所以我真的不知道如何解决这个问题。

    // get resource resolver
    ResourceResolver resourceResolver = resourceResolverFactory.getResourceResolver(Collections.<String, Object>singletonMap(JcrResourceConstants.AUTHENTICATION_INFO_SESSION, session));

    AssetManager assetMgr = resourceResolver.adaptTo(AssetManager.class);

    // creating directory in DAM Asset
    Node newParentNode = JcrUtil.createPath(splitParentPath, true, "sling:OrderedFolder", "nt:file", session, true);
    newParentNode.addNode("jcr:content", "nt:resource");

    // moving DAM Asset
    assetMgr.moveAsset(fileNode.getPath(), splitParentPath + "/" + newFileName); 

我确实遵循了这个 JCRUtil API https://helpx.adobe.com/experience-manager/6-2/sites/developing/using/reference-materials/javadoc/com/day/cq/commons/jcr/JcrUtil.html#createPath(Node,%20java.lang.String,%20boolean,%20java.lang.String,%20java.lang.String,%20Session,%20boolean), and this

请帮忙!

问题是 createPath 方法的自动保存标志已打开。这将尝试在您能够添加 jcr:content 子节点节点之前将节点提交到 repo。

添加子节点后尝试保存

// creating directory in DAM Asset
Node newParentNode = JcrUtil.createPath(splitParentPath, true, "sling:OrderedFolder", "nt:file", session, false);
newParentNode.addNode("jcr:content", "nt:resource");
session.save()