Namespaces (namespace prefixes) broken in Modeshape 2.7.0? Error converting String to a Name: b:test_6
martin-senne Jan 18, 2012 12:18 PMHi Randell, hi all,
as far as I can tell, namespace support seems to be broken in Modeshape 2.7.0.
For a valid session object I have set namespace
setNamespacePrefix("b", "http://abc.com");
and added some nodes named "b:test_1", "b:test_2", ... to the repository and called session.save() afterwards. Everything smooth up to that point. Now, using the following code excerpt, I want to do a query with JQOM to retrieve the node named b:test_3
// Obtain the query manager for the session ... QueryManager queryManager = session.getWorkspace().getQueryManager(); // Create a query object model factory ... QueryObjectModelFactory factory = queryManager.getQOMFactory(); ValueFactory valueFactory = session.getValueFactory(); // Create the FROM clause: a selector for the [nt:unstructured] nodes ... Selector source = factory.selector("nt:unstructured", "unstructNodes"); // Create the SELECT clause (we want all columns defined on the node type) ... Column[] columns = null; // Create the WHERE clause Constraint constraint = null; // EXPLICITLY WANT PropertyType.Name Value ourNodeName = valueFactory.createValue( filter.getValue().toString() , PropertyType.NAME ); // this fails either // Value ourNodeName = valueFactory.createValue( filter.getValue().toString() ); constraint = factory.comparison( // factory.nodeLocalName( "unstructNodes" ), factory.nodeName( "unstructNodes" ), QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, factory.literal( valueFactory.createValue( "b:test_3", PropertyType.NAME ) ) ); // Define the orderings (we have none for this query)... Ordering[] orderings = null; // Create the query ... QueryObjectModel query = factory.createQuery(source, constraint, orderings, columns); if (log.isDebugEnabled()) { log.debug("Query is '" + query + "'."); }
with the result :
DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule org.modeshape.jcr.query.RewritePseudoColumns@1e2c841 DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule ReplaceViews DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule CopyCriteria DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule RightOuterToLeftOuterJoins DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule AddAccessNodes DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule PushSelectCriteria DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule PushProjects DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule RewriteAsRangeCriteria javax.jcr.RepositoryException: Error while performing the query "Access [unstructNodes] Project [unstructNodes] Select [unstructNodes] Select [unstructNodes] Source [unstructNodes] " against the content in the "prod" workspace of the "__ALLNODES__" source: Error converting String to a Name: b:test_4 at org.modeshape.jcr.query.qom.JcrAbstractQuery.checkForProblems(JcrAbstractQuery.java:133) at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:104)
BUT performing the query via JCR_SQL2 (as follows) WORKS as expected:
// Obtain the query manager for the session ... QueryManager queryManager = session.getWorkspace().getQueryManager(); // String stmt = "SELECT * FROM [nt:unstructured] WHERE NAME() = '" + filter.getValue().toString()+"'"; String stmt = "SELECT * FROM [nt:unstructured] WHERE NAME() = CAST('" + filter.getValue().toString()+ "' AS NAME)"; Query query = queryManager.createQuery(stmt, Query.JCR_SQL2 ); QueryResult result = query.execute(); if (log.isDebugEnabled()) { log.debug("QueryResult is '" + result + "'."); }
with the result:
| # | jcr:primaryType | jcr:path | jcr:name | jcr:score | mode:localName | mode:depth | +---+-----------------+---------------+--------------+-------------------+----------------+------------+ | 1 | nt:unstructured | /ns001:test_4 | ns001:test_4 | 2.696368455886841 | test_4 | 1 |
By the way, doing the query ( //b:test_6 ) via XPath also results in an RepositoryException
DEBUG [main] (JcrNodeStore.java:304) - Query is : '//b:test_6'. DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule org.modeshape.jcr.query.RewritePseudoColumns@c5f468 DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule CopyCriteria DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule RightOuterToLeftOuterJoins DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule AddAccessNodes DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule PushSelectCriteria DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule PushProjects DEBUG [main] (SLF4JLoggerImpl.java:110) - Running query optimizer rule RewriteAsRangeCriteria javax.jcr.RepositoryException: Error while performing the query "Access [nodeSet1] Project [nodeSet1] Select [nodeSet1] Source [nodeSet1] " against the content in the "prod" workspace of the "__ALLNODES__" source: Error converting String to a Name: b:test_6 at org.modeshape.jcr.query.qom.JcrAbstractQuery.checkForProblems(JcrAbstractQuery.java:133) at org.modeshape.jcr.query.JcrQuery.execute(JcrQuery.java:104)
Any help is appreciated and thanks alot.. Martin