aemjcr

Why does a JCR SQL 2 Query for nt:unstructured also return cq:PageContent nodes?


I have the following JCR SQL 2 query:

SELECT * FROM [nt:unstructured] as node
         WHERE isDescendantNode(node, '/content/some/root/path')
         AND # EXTRA CONDITIONS

and the result set, along with a bunch of nt:unstructured nodes, returns a lot of nodes with the cq:PageContent primary type. When inspected in CRX DE, it's clear that their jcr:primaryType is cq:PageContent, not nt:unstructured

Why is this happening?


Solution

  • Each node type in JCR can have supertypes.

    3.7.1.2 Supertypes

    A node type has zero or more supertypes. Supertypes are specified by name.

    which can be organised into an inheritance hierarchy.

    In case of this particular query, where the nt:unstructured node type is used, cq:PageContent nodes appear in the result set because their jcr:primaryType is a subtype of nt:unstructured.

    This is described in the documentation for AEM custom node types.

    [cq:PageContent] > nt:unstructured, mix:title, mix:created, cq:OwnerTaggable, sling:VanityPath, cq:ReplicationStatus, sling:Resource orderable

    • cq:template (string)
    • cq:allowedTemplates (string) multiple
    • pageTitle (string)
    • navTitle (string)
    • hideInNav (boolean)
    • onTime (date)
    • offTime (date)
    • cq:lastModified (date)
    • cq:lastModifiedBy (string)
    • cq:designPath (string)
    • jcr:language (string)

    The query, depending on the other conditions, is likely to return nodes with other types explicitly listed as the jcr:primaryType, which also inherit from nt:unstructured. Some examples include: cq:EditConfig, dam:AssetContent, cq:LiveSyncAction and many more.