What is the difference between jcr:primaryType and jcr:mixinTypes?

yash ahuja picture yash ahuja · Apr 15, 2014 · Viewed 12.2k times · Source

I am just curious to know what is the difference between jcr:primaryType and jcr:mixinTypes, and why exactly does jcr:mixinTypes is used ? what does it signifies ? If you check /content/dam folder in crx it shows jcr:primaryType property value as sling:OrderedFolder and jcr:mixinTypes as mix:lockable,rep:AccessControllable where jcr:primaryType means this a sling folder but why mixin type. Also went through these docs http://www.day.com/specs/jcr/1.0/6.7.4_Primary_and_Mixin_Node_Types.html http://www.day.com/specs/jcr/1.0/6.7.5_Special_Properties_jcr_primaryType_and_jcr_mixinTypes.html but yet doesn't gives much insight to the difference.

Thanks.

Answer

Bertrand Delacretaz picture Bertrand Delacretaz · Apr 16, 2014

A Node can have only one jcr:primaryType but it can have several jcr:mixinTypes, so it is correct to see the mixins as "traits" or additional aspects of a node.

While http://wiki.apache.org/jackrabbit/DavidsModel "Data First, Structure Later. Maybe" rule recommends using primary node types sparingly due to the strong constraints that they usually imply, mixins are much less constraining and very useful to identify nodes as having specific uses or properties.

The mix:lockable mixin that you mention, for example, is used to express that a node can be locked. As per http://www.day.com/specs/jcr/2.0/17_Locking.html, only nodes with mixin node type mix:lockable may hold locks. Any type of node can potentially be locked, so using a node type for that wouldn't work.