0

The following code snippet:

GraphDatabaseService graphDb = new EmbeddedGraphDatabase("var/geo");
// Wrap it as a spatial db service
SpatialDatabaseService spatialDb = new SpatialDatabaseService(graphDb);
// Create the layer to store our spatial data
EditableLayer runningLayer = (EditableLayer) spatialDb.getOrCreateLayer("running", SimplePointEncoder.class, EditableLayerImpl.class, "lon:lat");

fails with the error:

Exception in thread "main" java.lang.ClassCastException: org.neo4j.collections.graphdb.impl.EmbeddedGraphDatabase cannot be cast to org.neo4j.kernel.GraphDatabaseAPI
at org.neo4j.cypher.ExecutionEngine.<init>(ExecutionEngine.scala:113)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:53)
at org.neo4j.cypher.javacompat.ExecutionEngine.<init>(ExecutionEngine.java:43)
at org.neo4j.collections.graphdb.ReferenceNodes.getReferenceNode(ReferenceNodes.java:60)
at org.neo4j.gis.spatial.SpatialDatabaseService.getSpatialRoot(SpatialDatabaseService.java:76)
at org.neo4j.gis.spatial.SpatialDatabaseService.getLayer(SpatialDatabaseService.java:108)
at org.neo4j.gis.spatial.SpatialDatabaseService.getOrCreateLayer(SpatialDatabaseService.java:202)
at com.bmt.contain.spatial.test.SpatialTest.main(SpatialTest.java:47)

I was trying to get the sample code from here to work, I have included the relevant import statements below, in case I am somehow importing the wrong version of a function.

import org.neo4j.collections.graphdb.impl.EmbeddedGraphDatabase;

import org.neo4j.graphdb.GraphDatabaseService;

import org.neo4j.gis.spatial.EditableLayer;
import org.neo4j.gis.spatial.EditableLayerImpl;
import org.neo4j.gis.spatial.Layer;
import org.neo4j.gis.spatial.encoders.SimplePointEncoder;

Can someone advise me?

Also, its 2.0.1 for both neo4j and v13 for spatial.

<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j-spatial</artifactId>
    <version>0.13-neo4j-2.0.1</version>
</dependency>
<dependency>
    <groupId>org.neo4j</groupId>
    <artifactId>neo4j</artifactId>
    <version>2.0.1</version>
</dependency>
phil_20686
  • 4,000
  • 21
  • 38

1 Answers1

0

So the answer to this question is that you need to use

GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/geo");

instead of

GraphDatabaseService graphDb = new EmbeddedGraphDatabase("var/geo");

Somewhere under the hood this creates a different type of Embedded GDbS which doesnt cause a class cast exception.

phil_20686
  • 4,000
  • 21
  • 38