所以我试图了解Neo4j Spatial。我写了以下代码:
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();
}
}
这似乎是我第一次运行它,但如果我尝试第二次运行它,我会得到:
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
所以我理解这通常是某种版本控制,所以下面是我从有效POM中获得的maven依赖项(以及许多其他版本)。
<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:我也很感激理解为什么SO代码没有用优秀的突出显示来解析Java代码。
答案 0 :(得分:1)
这与neo4j空间无关。您的neo4j依赖项似乎已升级到新版本。因此,您的数据存储也需要升级。
请确保在升级之前进行备份复制。不支持数据存储区降级。
要执行数据存储区升级,请创建GraphDatabaseService
,如下所示:
GraphDatabaseService graphDb = new GraphDatabaseFactory()
.newEmbeddedDatabaseBuilder("var/geo")
.setConfig("allow_store_upgrade", "true")
.newGraphDatabase();
答案 1 :(得分:0)
原来这是一个maven问题。
通过将存储库更改为:
<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>
依赖于:
<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>
问题消失了。我以前一直使用http://maven-repository.com/artifact/org.neo4j/neo4j-spatial作为我的maven存储库,似乎这些版本在某种程度上不兼容。