JCR Session.itemExists or nodeExists returns pathnotfound exception instead of true or false | Community
Skip to main content
vikramca06
Level 4
Jan 30, 2019 5:33 PM UTC
Solved

JCR Session.itemExists or nodeExists returns pathnotfound exception instead of true or false

Hi All,

I am trying to check if a node exist under a path and set some property. but when i try to check a path through session it returns PathNotFoundException instead of true/false.

if(!destSession.nodeExists(dRootPath)) / if(!destSession.itemExists(dRootPath))

is there any other way?

Regards,

Vikram.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
joerghoh
joerghohAccepted solution
Employee
Jan 31, 2019 9:59 PM UTC

According to the stacktrace you get the exception in the "session.getNode()" API call, not in "session.nodeExists()". Thus it's perfectly valid.

8 replies

joerghoh
joerghohAccepted solution
Employee
Jan 31, 2019 9:59 PM UTC

According to the stacktrace you get the exception in the "session.getNode()" API call, not in "session.nodeExists()". Thus it's perfectly valid.

Translate
antoniom5495929
Level 7
Jan 31, 2019 7:34 PM UTC

Hi,

could you attach the entire java class? Just to try to reproduce it.

Thanks,

Antonio

Translate
vikramca06
Level 4
Jan 31, 2019 2:43 AM UTC

Hi All,

please find the sample code (using admin session) and exception below.

@smacdonald2008

to use hasNode() from Node API we need to have the root node. i am trying to check the root node with session and then get it.

if(!destSession.nodeExists(dFolderPath)) {

log.info("Node not found. creating : " + dFolderPath);

Node rootFolderNode = destSession.getNode(dParentPath);

}else{

log.info("Folder Exist : " + dFolderPath);

}

Exception:

javax.jcr.PathNotFoundException: /content/dam/geometrixx/migration/snowboarding

at org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntryImpl.getDeepNodeEntry(NodeEntryImpl.java:395) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyManagerImpl.getNodeEntry(HierarchyManagerImpl.java:137) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.ItemManagerImpl.getNode(ItemManagerImpl.java:168) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

at org.apache.jackrabbit.jcr2spi.SessionImpl.getNode(SessionImpl.java:513) ~[jackrabbit-jcr2spi-2.10.0.jar:na]

Translate
smacdonald2008
Level 10
Jan 30, 2019 7:37 PM UTC

For testing sake - use the admin login call to get session and whitelist the OSGi bundle. See if the API works properly then.

Translate
antoniom5495929
Level 7
Jan 30, 2019 7:35 PM UTC

Hi,

could you post the stacktrace? It seems an interesting behavior.

Thanks,

Antonio

Translate
smacdonald2008
Level 10
Jan 30, 2019 7:07 PM UTC

Use javax.jcr.Node's method named hasNode() - see Javadocs.

Node (Content Repository for Java Technology API Version 2.0) 

This method returns false if this node does not exist.

Translate
vikramca06
Level 4
Jan 30, 2019 6:02 PM UTC

i am using service user with admin rights. for now the node is not exist, in future it might be. so i want to check if the node exist or not then set property.

As per Session (Content Repository for Java Technology API Version 2.0) it should return true/false

Regards,

Vikram

Translate
Gaurav-Behl
Level 10
Jan 30, 2019 5:36 PM UTC

How are you getting the session? Does the service-user that you use has "read" access on that path?

Translate