Expand my Community achievements bar.

SOLVED

Getting repository exception on executing query (inner join) in CQ5.6

Avatar

Level 4

Hi,

I am running an INNER JOIN query(javax.jcr.query.Query). I am getting an exception:

javax.jcr.RepositoryException: This query result contains more than one selector .

However when I am running this query directly in CRXDE it runs fine. Any idea.

Sample query:

SELECT parent.* FROM [cq:Page] AS parent INNER JOIN [nt:base] AS child ON ISCHILDNODE(child,parent) WHERE ISDESCENDANTNODE(parent, '/content') and NAME(child) = 'status'AND child.[cq:template] = '/libs/cq/personalization/templates/campaign'

Regards,

Shallu Rohilla

1 Accepted Solution

Avatar

Correct answer by
Employee Advisor

Instead of using query.execute().getNodes() method use the following snippet to get the iterator- 

final QueryResult result = query.execute();final RowIterator iterator = result.getRows(); while (iterator.hasNext()) { final Row row = iterator.nextRow(); Node node = session.getNode(row.getPath("parent")); }

View solution in original post

5 Replies

Avatar

Employee Advisor

If you are using JCR API to execute this SQL2 query then you will have to use a different method to get the node returned by the query. 

//Normal SQL2 query execution final RowIterator iterator = result.getRows(); while (iterator.hasNext()) { final Row row = iterator.nextRow(); Node node = row.getNode(); } //for multiple selectors you need to use the following method final RowIterator iterator = result.getRows(); while (iterator.hasNext()) { final Row row = iterator.nextRow(); Node node = session.getNode(row.getPath(“parent”)); }

 

Reference - https://issues.apache.org/jira/browse/JCR-3089

Avatar

Level 4

Actually I am getting error on calling query.execute method itself(see the underlined code).

        QueryManager queryManager = session.getWorkspace().getQueryManager();
        Query query = queryManager.createQuery(statement, Query.JCR_SQL2);
        query.setLimit(nodeSearchCriteria.getLimit());
        query.setOffset(nodeSearchCriteria.getStart());
        final NodeIterator iterator = query.execute().getNodes();

 

Regards,

Shallu Rohilla

Avatar

Correct answer by
Employee Advisor

Instead of using query.execute().getNodes() method use the following snippet to get the iterator- 

final QueryResult result = query.execute();final RowIterator iterator = result.getRows(); while (iterator.hasNext()) { final Row row = iterator.nextRow(); Node node = session.getNode(row.getPath("parent")); }

Avatar

Level 10

Hi Shallu,

Are you executing this query via OSGI service? If yes, Can you please share the code snippet.

Meanwhile please take a look at Community article on it @ https://helpx.adobe.com/experience-manager/using/querying-experience-manager-data-using1.html