cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

User defined function: Failed to invoke function Caused by: java.lang.NoSuchMethodError

ruko
Node

Hello,
I am playing around with the plugin system of neo4j.
I just want to call my function with an ID and want the neighbours of this node returned as a String:

public class Neighbours {
    @Context
    public GraphDatabaseService db;

    @UserFunction
    public String neighbours(@Name("nodeId") long nodeId) {
        Node node = db.findNode(Label.label(""), "id", nodeId);
        return StreamSupport.stream(node.getRelationships().spliterator(), false)
                .map(neighbourNode -> neighbourNode.getProperty("id").toString())
                .collect(Collectors.joining(", "));
    }
}

Calling my function causes this error:

Neo.ClientError.Procedure.ProcedureCallFailed
Failed to invoke function `example.neighbours`: Caused by: java.lang.NoSuchMethodError: org.neo4j.graphdb.GraphDatabaseService.findNode(Lorg/neo4j/graphdb/Label;Ljava/lang/String;Ljava/lang/Object;)Lorg/neo4j/graphdb/Node;

I also tried other methods of GraphDatabaseService, no luck.
What is wrong with my function? I am using neo4j-community-4.0.4.

Also I do not have any labels on my nodes. Would my above implementation work to retrive my label-less nodes or do I have to use null as parameter?

//edit: ok, seems like the procedure-template on github ist for neo4j 3.x and I am using 4.x.
Is there any documentation on how to do this in the newer Neo4j?

4 REPLIES 4

mark_needham
Neo4j
Neo4j

We need to fix the lack of procedure template!In the meantime, you can find some example in Max De Marzi's blog:

ruko
Node

I had to update the version numbers in the pom.xml and first begin a transaction.
Now I can call findNode on the transaction object to retrieve a node.
But I cannot figure out how to find a node which does not have a label present.

Node node = tx.findNode(Label.label(""), "id", nodeId);

This does not return any node. I also tried with * as label and with null (which causes a NPE), but nothing works.

Node node = tx.findNode(Label.label(""), "id", nodeId);

This method is trying to find using property named "id". This is similar to

MATCH (n) where n.id=nodeId

I don't think that is correct way to retrieve node by it's node id.

Can you try

Node node = tx.getNodeById​(nodeId)

This will retrieve the node by it's nodeId.

mark_needham
Neo4j
Neo4j

I think you may have to find the node via the tx.getAllNodes() function and then check the property on each node until you find the one you want.