Sling API vs JCR API
AEM supports the use of both Sling APIs and JCR APIs.
- Docs on best practices
https://experienceleague.adobe.com/docs/experience-manager-learn/foundation/development/understand-java-api-best-practices.html?lang=en - Docs on Sling API
https://sling.apache.org/old-stuff/sling-api.html - Docs on JCR API
https://experienceleague.adobe.com/docs/experience-manager-65/developing/platform/access-jcr.html?lang=en
https://developer.adobe.com/experience-manager/reference-materials/spec/javax.jcr/javadocs/jcr-2.0/index.html
The docs mention "While the JCR is AEM’s content repository, its APIs are NOT the preferred method for interacting with the content. Instead prefer the AEM APIs (Page, Assets, Tag, and so on) or Sling Resource APIs as they provide better abstractions."
Furthermore, "Broad use of JCR APIs’ Session and Node interfaces in an AEM application is code-smell. Ensure Sling APIs should be used instead."
Personally, I used the JCR API for creating nodes and properties in custom workflows.
And found it necessary to use the JCR API in the unit tests.
Did you personally come across any use cases where the JCR API is better than the sling API?
And is it always a legitimate code smell?