Reputation: 4080
So I am trying to get my head around Neo4j Spatial. I wrote the following code:
public static void main(String[] args) {
GraphDatabaseService graphDb = new GraphDatabaseFactory().newEmbeddedDatabase("var/geo");
SpatialDatabaseService spatialDb = new SpatialDatabaseService(graphDb);
EditableLayer runningLayer = (EditableLayer) spatialDb.getOrCreateLayer("running", SimplePointEncoder.class, EditableLayerImpl.class, "lon:lat");
Node ship = null;
try(Transaction tx = graphDb.beginTx();) {
ship = graphDb.createNode(MyLabels.Ship);
ship.setProperty("Name", new String("Toms Powerboat"));
tx.success();
}
routeGenerator(graphDb, runningLayer, ship);
graphDb.shutdown();
}
private static void routeGenerator(GraphDatabaseService graphDb, EditableLayer runningLayer, Node node){
final long startTime = System.currentTimeMillis();
try(
Transaction tx = graphDb.beginTx();
){
Coordinate start = new Coordinate(Math.random()*10, Math.random()*10);
for(int i=0; i<200; i++){
SpatialDatabaseRecord torecord = runningLayer.add(runningLayer.getGeometryFactory().createPoint(start));
torecord.setProperty("Time", (System.currentTimeMillis() - startTime)*10000000);
torecord.getGeomNode().createRelationshipTo(node, RelTypes.hasLocation);
start = new Coordinate((start.x + 0.1), start.x+Math.random()*0.2);
}
tx.success();
}
}
This appears to work the first time that I run it, but if I try to run it a second time I get :
Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, C:\Users\pstephens\Programming\Java\ContainSSS\var\geo
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:63)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:92)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:198)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
at com.bmt.contain.spatial.test.SpatialTest.main(SpatialTest.java:43)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.transaction.XaDataSourceManager@349cebe0' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:307)
... 5 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource@46c8fa1e' was successfully initialized, but failed to start. Please see attached cause exception.
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:509)
at org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
at org.neo4j.kernel.impl.transaction.XaDataSourceManager.start(XaDataSourceManager.java:164)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 7 more
Caused by: org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException: Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
at org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:71)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:144)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:119)
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.start(NeoStoreXaDataSource.java:323)
at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
... 10 more
So I understand that this is usually some kind of versioning, so below is the maven dependencies that I have (among many others) from the effective POM.
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-spatial</artifactId>
<version>0.13-neo4j-2.0.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.0.1</version>
<scope>compile</scope>
</dependency>
PS: I would also appreciate understanding why the Java code is not being parsed by SO with the nice highlighting.
Upvotes: 1
Views: 108
Reputation: 4080
This turned out to be a maven problem.
By changing the repositories to:
<repository>
<id>neo4j-contrib-releases</id>
<url>https://raw.github.com/neo4j-contrib/m2/master/releases</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>neo4j-contrib-snapshots</id>
<url>https://raw.github.com/neo4j-contrib/m2/master/snapshots</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
And the dependencies to:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-spatial</artifactId>
<version>0.12-neo4j-2.0.2</version>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.0.2</version>
</dependency>
The problem went away. I had previously been using https://mvnrepository.com/artifact/org.neo4j/neo4j-spatial as my maven repository, and it seems these versions are somehow not compatible.
Upvotes: 0
Reputation: 39925
This is not related to neo4j spatial. It seems your neo4j dependencies have been upgraded to a new version. Therefore you datastore need to be upgraded as well.
PLEASE MAKE SURE TO MAKE A BACKUP COPY PRIOR TO UPGRADING. Datastore downgrades are not supported.
To perform the datastore upgrade create your GraphDatabaseService
like this:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder("var/geo")
.setConfig("allow_store_upgrade", "true")
.newGraphDatabase();
Upvotes: 1