7 Replies Latest reply on Jan 3, 2012 2:38 PM by alex soto

    Join not returning results

    alex soto Newbie

      Hello:

       

      I am having trouble with this query not returning expected results:

       

                          final Session session = repository.login(new SimpleCredentials(getUserName(), getPassword().toCharArray()));
        
                          final String friendlyNodeType = "tt:friendly";
                          final String friendPropertyName = "tt:friend";
        
                          final NamespaceRegistry registry = session.getWorkspace().getNamespaceRegistry();
                          registry.registerNamespace("tt", "http://test.com/tt");
        
                          final NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
                          final NodeTypeTemplate nodeType = manager.createNodeTypeTemplate();
                          nodeType.setMixin(true);
                          nodeType.setName(friendlyNodeType);
                          nodeType.setQueryable(true);
                          nodeType.setDeclaredSuperTypeNames(new String[]{"mix:referenceable"});
        
                          final PropertyDefinitionTemplate propertyDef = manager.createPropertyDefinitionTemplate();
                          propertyDef.setName(friendPropertyName);
                          propertyDef.setMultiple(true);
                          propertyDef.setRequiredType(PropertyType.REFERENCE);
                          propertyDef.setOnParentVersion(OnParentVersionAction.COPY);
                          propertyDef.setProtected(false);
        
                          nodeType.getPropertyDefinitionTemplates().add(propertyDef);
                          manager.registerNodeType(nodeType, true);
        
                          final Node granteeNode = session.getRootNode().addNode("Paul", "nt:folder");
                          granteeNode.addMixin(friendlyNodeType);
      
                          final Node grantorNode = session.getRootNode().addNode("Pedro", "nt:folder");
                          grantorNode.addMixin(friendlyNodeType);
        
                          final ValueFactory valueFactory = session.getValueFactory();
                          final Value granteeValue = valueFactory.createValue(granteeNode);
                          grantorNode.setProperty(friendPropertyName, new Value[]{granteeValue});
      
                          session.save();
      
                          final QueryManager queryManager = session.getWorkspace().getQueryManager();
                          final String expression = 
        "SELECT grantee.* FROM [tt:friendly] as grantee " +
        "INNER JOIN [tt:friendly] as grantor " +
        "ON grantee.[jcr:uuid] = grantor.[tt:friendly]";
        
                          final Query query = queryManager.createQuery(expression, "JCR-SQL2");
                          final QueryResult queryResult = query.execute();
                          Assert.assertEquals(1, queryResult.getRows().getSize());
      
      

       

      I am using version 2.7.0.Final

      I expect the query to rerturn Paul's node.

      (It works with JackRabbit)

       

      Thanks