为何JCR SQL 2查询nt:unstructured会返回cq:PageContent节点?
JCR SQL2 查询返回cq:PageContent节点的原因及解决办法
问题背景
执行以下JCR SQL2查询:
SELECT * FROM [nt:unstructured] as node WHERE isDescendantNode(node, '/content/some/root/path') AND # EXTRA CONDITIONS
查询结果中除了预期的nt:unstructured节点外,还包含大量主类型为cq:PageContent的节点,而这些节点在CRX DE中明确显示jcr:primaryType为cq:PageContent。
原因分析
这是JCR规范的默认行为:当查询指定某个节点类型时,会自动匹配所有继承该类型的子类型节点。
在AEM的节点类型体系中,cq:PageContent的继承链为:cq:PageContent → nt:unstructured → nt:base。也就是说,cq:PageContent是nt:unstructured的直接子类型,所以查询nt:unstructured时会包含所有cq:PageContent节点。
解决办法
如果只想精确获取主类型为nt:unstructured的节点,需要在查询中额外添加条件,明确限定jcr:primaryType的值,修改后的查询如下:
SELECT * FROM [nt:unstructured] as node WHERE isDescendantNode(node, '/content/some/root/path') AND node.[jcr:primaryType] = '[nt:unstructured]' AND # EXTRA CONDITIONS
这样就能过滤掉cq:PageContent等子类型节点,只返回符合要求的nt:unstructured节点。
内容的提问来源于stack exchange,提问作者toniedzwiedz
相关产品推荐
相关产品推荐

