I'm using an sql2 query to fetch all the home pages from different locales based on sling:resourceType and my query is below. I'm using system user to get the resolver. FYI.
SELECT * FROM [cq:Page] AS s WHERE s.[jcr:content/sling:resourceType] = 'sample/components/structure/pageHome' AND ISDESCENDANTNODE('/content/sample')
The above query is working fine in my local . But in Development environment I'm unable to fetch the home pages using this query from backend, whereas the same query I tried with crx/de query search where I'm able to fetch the homepages. I tried the below things but no luck,
Checked the system user permissions in user admin (which I used to get the resolver) and I'm having read, modify, delete, readACL, editACL for all .
Checked the backend logs. After executing the above query from backend I'm getting zero results. So, suspecting it should be permission issue. Can anyone help me to fix this?
Could you share the service user mapping xml/screenshot?
Is the code-bundle where this query is written, given appropriate permissions via service user mapping?
Does that service user has read (or appropriate) access on the folder path where your query runs (/content/sample)?
Could you enable logging on your package/query to see the error in logs?
Try to use AEM Chrome plugin: AEM Chrome Plug-in - Chrome Web Store,
It will allow you to see teh exact query that your code executes, determine if it's traversal and hence you need to work with indexes and test the query output from AEM Chrome Plugin in AEM Explain Query tool.
The state of the bundle is in active and the service is also in active. That's why I could able to see the logs which I put in that service.
If the issue with archtype or dependencies then it should not work in local as well right? but for me it is working in local. Issue is only wth the dev environment.
Hi Arun Patidar,
I have changed the code as you suggested (using repository session). But still I'm facing the same issue. The updated code is working fine in my local instance but not in dev. Also I' having some existing projects in dev environment where I'm using the same logic (get all locale based home pages) and the same code is working for those projects. But the same code is not working in fresh/new project. In logs I could see the sql2 query which got executed and it return zero results whereas the same query I tried with crx/de query search and I'm getting the proper results..FYI. I checked with Apache Sling Service User Mapper Service Amendment and I'm having proper mappings as well. Any other clue on this?
The query is : SELECT * FROM [cq:Page] AS s WHERE s.[jcr:content/sling:resourceType] = 'sample/components/structure/pageHome' AND ISDESCENDANTNODE('/content/sample')
I believe there is no issue in the query
How did you get the session, the session should be repository session.
|private SlingRepository repository;|
session = repository.loginService("readService",null);
final Query query=session.getWorkspace().getQueryManager().createQuery("yourquery",Query.JCR_SQL2);