Expand my Community achievements bar.

SOLVED

QueryResult return No Results in OSGI while returns results in CRXDE Query Tool

Avatar

Level 3

I have seen a couple posts here related to a similar issue, where JCR-SQL2 query returns 3 results in CRXDE Query Tool but 0 results in OSGI. 

wenwang1_0-1683317965382.png

 

Here's my code:

String query = "SELECT DISTINCT page.[jcr:path] FROM [cq:Page] AS page...";
Session session = resourceResolver.adaptTo(Session.class);
QueryManager queryManager = session.getWorkspace().getQueryManager();
Query query = queryManager.createQuery(query, Query.JCR_SQL2);
QueryResult queryResult = query.execute();
String mycontent = new String();
if (queryResult.getNodes() != null) {
NodeIterator nodeIterator = queryResult.getNodes();
while (nodeIterator.hasNext()) {
Node node = nodeIterator.nextNode();
String path = node.getPath();
mycontent += path;
}
}

The variable mycontent returns empty. Am I missing something? I tried to look into the queryResult but there's no return values inside. When I use breakpoint, it shows nodeIterator.hasNext() return false.. 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Your code picks the current user session to get the result. So, the current user may not have to read permission to those content paths.

Alternatively, could you print the query in the logs by your code and then run it in the CRXDE query tool? 

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Your code picks the current user session to get the result. So, the current user may not have to read permission to those content paths.

Alternatively, could you print the query in the logs by your code and then run it in the CRXDE query tool?