blog.relativt.net

Eirik's public note to self

13 April 2013

Spring Data Neo4j, Neo4jTemplate, and Cypher queries

by Eirik Tenold

Yesterday, I tried to get Spring Data Neo4j’s Neo4jTemplate to work with a Neo4j server via REST. I got an error when I tried to run Cypher queries over REST. The only thing I got was an exception:

java.lang.UnsupportedOperationException: null
 at org.neo4j.rest.graphdb.AbstractRemoteDatabase.getNodeManager(AbstractRemoteDatabase.java:136)
 at org.neo4j.rest.graphdb.RestGraphDatabase.getNodeManager(RestGraphDatabase.java:33)
 at org.neo4j.tooling.GlobalGraphOperations.<init>(GlobalGraphOperations.java:39)
 at org.neo4j.tooling.GlobalGraphOperations.at(GlobalGraphOperations.java:51)
 at org.neo4j.cypher.internal.spi.gdsimpl.GDSBackedQueryContext$$anon$1.all(GDSBackedQueryContext.scala:86)
 at org.neo4j.cypher.internal.executionplan.builders.GraphGlobalStartBuilder$$anonfun$createStartPipe$1.apply(GraphGlobalStartBuilder.scala:50)

This was strange, since all other operations seemed to work fine. After a couple of hours worth of debugging, I found the problem; the SpringRestGraphDatabase should be casted to GraphDatabase, not GraphDatabaseService.

This does not work:

SpringRestGraphDatabase springRestGraphDatabase = new SpringRestGraphDatabase("http://localhost:7474/db/data");
Neo4jTemplate neo4jTemplate = new Neo4jTemplate((<i><b>GraphDatabaseService</b></i>) springRestGraphDatabase);
org.springframework.data.neo4j.conversion.Result&lt;Map&lt;String, Object&gt;&gt; query = neo4jTemplate.query("start n=node(*) return n", null);

This works:

SpringRestGraphDatabase springRestGraphDatabase = new SpringRestGraphDatabase("http://localhost:7474/db/data");
Neo4jTemplate neo4jTemplate = new Neo4jTemplate((<i><b>GraphDatabase</b></i>) springRestGraphDatabase);
org.springframework.data.neo4j.conversion.Result&lt;Map&lt;String, Object&gt;&gt; query = neo4jTemplate.query("start n=node(*) return n", null);
tags: Spring Data - Neo4j - Spring Data Neo4j - Graph database