You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by NAO <Ne...@csiro.au> on 2009/03/02 04:57:34 UTC

Checking for null reference properties

I have been trying to run a query to collect all the nodes where a reference
property has been set.

The SQL query string 

Query q = queryManager.createQuery("select * from ala:TypeA where
ala:typeBRef is not null",Query.SQL);


works where ala:typeBRef is defined as a string value, but if it has been
defined as a reference, the search returns no nodes regardless of what
getProperty returns.

Could someone please explain to me why this should be the case, and how I
can do a global search for the nodes where a reference link exists?


-- 
View this message in context: http://www.nabble.com/Checking-for-null-reference-properties-tp22281732p22281732.html
Sent from the Jackrabbit - Users mailing list archive at Nabble.com.


Re: Checking for null reference properties

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi,

I quickly tried this out and it worked as expected:

    public void testRefProp() throws RepositoryException {
        Node n = testRootNode.addNode(nodeName1);
        n.addMixin(mixReferenceable);
        Node n2 = testRootNode.addNode(nodeName2);
        n2.setProperty(propertyName1, n);
        testRootNode.save();
        executeXPathQuery(testPath + "/*[@" + propertyName1 + "]", new
Node[]{n2});
        executeSQLQuery("select * from nt:base where " + propertyName1
                + " is not null and jcr:path like '" + testRoot +
"/%'", new Node[]{n2});
    }


On Mon, Mar 2, 2009 at 04:57, NAO <Ne...@csiro.au> wrote:
>
> I have been trying to run a query to collect all the nodes where a reference
> property has been set.
>
> The SQL query string
>
> Query q = queryManager.createQuery("select * from ala:TypeA where
> ala:typeBRef is not null",Query.SQL);
>
>
> works where ala:typeBRef is defined as a string value, but if it has been
> defined as a reference, the search returns no nodes regardless of what
> getProperty returns.
>
> Could someone please explain to me why this should be the case, and how I
> can do a global search for the nodes where a reference link exists?

are you searching for nodes that have a reference property, or do you
rather want the nodes that are referenced? If it's the latter you can
use the jcr:deref() function (only available in XPath):

//element(*, nt:base)/jcr:deref(@ala:typeBRef, '*')

returns all nodes that are referenced by a ala:typeBRef property.

see also: http://www.day.com/specs/jcr/1.0/6.6.5.4_jcr_deref_Function.html

regards
 marcel