cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to call APOC functions from Java?

Hello everyone.
I have a Java app working with Neo4j and APOC.
I'm facing a problem calling an APOC function from java, which is apoc.text.join.
When I run a Cypher query I got this error:
org.neo4j.cypher.SyntaxException: Unknown function 'apoc.text.join'
My register function is:

private static void registerApocProcedure(GraphDatabaseService graphDB) throws IllegalArgumentException {
		//Register APOC procedures
		Procedures procedures = ((GraphDatabaseAPI) graphDB).getDependencyResolver().resolveDependency(Procedures.class);
		List<Class<?>> apocProcedures = Arrays.asList(Xml.class, GraphRefactoring.class, apoc.text.Strings.class);
		apocProcedures.forEach((proc) -> {
			try {
				procedures.registerProcedure(proc);
			} catch (KernelException e) {
				throw new RuntimeException("Error registering "+proc,e);
			}
		});
	}

I recently added apoc.text.Strings.class where it's supposed to be the Join function, but it doesn't work.
I also tried to install Neo4j with APOC plugin and run the embedded browser, the same queries with apoc.text.join work fine!
Calling: CALL apoc.help('apoc.text.join'), apoc.text.join is marked as a function.

So, is the way of calling a APOC function in Java different?
Am I doing something wrong?
Many thanks!

1 ACCEPTED SOLUTION

You also have to call procedures.registerFunction(proc) with each class.

View solution in original post

5 REPLIES 5

You also have to call procedures.registerFunction(proc) with each class.

Can any one help how can we call the predefined apoc from java application. I am creating my own apoc in which i want to call apoc.load.jdbc. How can i do that

The same way you call other cypher statements. With db.execute(statement, params) in the Java API of the injected graph database service.

Thank Michael. Do I need to register the procedure before the executing ?

I made below custom procedure for just to test
public Stream loadPlan(@Name(value="planCode")String planCode){

	String str="This is the plan"+planCode;
	List<String> alpha = Arrays.asList(str);
	
	return alpha.stream().map(planName-> new PlanDTO(str));
	//return str.chars().mapToObj();	
}

now I want to test this apoc via another Java class .

will this syntax can be used to run function from java class also ???
db.execute(statement, params)