QueryResult return No Results in OSGI while returns results in CRXDE Query Tool | Community
Skip to main content
Level 3
May 5, 2023
Solved

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

  • May 5, 2023
  • 1 reply
  • 566 views

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. 

 

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.. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by rawvarun

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? 

1 reply

rawvarun
Community Advisor
rawvarunCommunity AdvisorAccepted solution
Community Advisor
May 5, 2023

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?