有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

在JDK1.7中使用neo4j时出现java错误

我正在使用Java 1.7和neo4j-community-2.0-1.1构建一个示例neo4j图形数据库。请看下面我的代码

 import org.neo4j.graphdb.Direction;
 import org.neo4j.graphdb.GraphDatabaseService;
 import org.neo4j.graphdb.Node;
 import org.neo4j.graphdb.Relationship;
 import org.neo4j.graphdb.RelationshipType;
 import org.neo4j.graphdb.Transaction;
 import org.neo4j.graphdb.factory.GraphDatabaseFactory;

 public class showData {

private static final String Neo4J_DBPath = "/Technology/neo4j-community-2.0-1.1";
/**
 * @param args
 */

Node first;
Node second;
Relationship relation;
GraphDatabaseService graphDataService;

//List of relationships
private static enum RelationshipTypes implements RelationshipType
{
    KNOWS
}


public static void main(String[] args) 
{
    showData data = new showData();
    data.createDatabase();
    data.removeData();
    data.shutDown();

}

void createDatabase()
{
   //GraphDatabaseService
   graphDataService = new GraphDatabaseFactory().newEmbeddedDatabase(Neo4J_DBPath);                                    

   // Begin transaction
       Transaction transaction = graphDataService.beginTx();

   try
   {
    // create nodes and set the properties the nodes
    first = graphDataService.createNode();
    first.setProperty("Name", "Ravneet Kaur");

    second = graphDataService.createNode();
    second.setProperty("Name", "Harpreet Singh");

    //specify the relationships

    relation = first.createRelationshipTo(second,   RelationshipTypes.KNOWS);
    relation.setProperty("relationship-type", "knows");
    //success transaction
    System.out.println(first.getProperty("name").toString());
    System.out.println(relation.getProperty("relationship-type").toString());
    System.out.println(second.getProperty("name").toString());

    transaction.success();
  }
  finally
  {
      transaction.finish();
  }

}

void removeData()
{
    Transaction transaction = graphDataService.beginTx();
    try
    {
         first.getSingleRelationship(RelationshipTypes.KNOWS,Direction.OUTGOING).delete();
        System.out.println("Nodes are deleted");
        //delete the nodes
        first.delete();
        second.delete();
        transaction.success();
    }
    finally
    {
        transaction.finish();
    }

}

void shutDown()
{
    graphDataService.shutdown();
    System.out.println("Database is shutdown");
}

}

早些时候,我使用Jave 1.6来编译这段代码,但我知道这个neo4j jar符合jdk 1.7。所以我把它改成了JDK1.7,并对eclipse中安装的JRE、执行环境和Java构建路径进行了所有必要的更改,以指向最新的Java。 现在我得到以下错误

Exception in thread "main" java.lang.RuntimeException: Error starting org.neo4j.kernel.EmbeddedGraphDatabase, /Technology/neo4j-community-2.0-1.1
    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.PNL.data.neo4j.showData.createDatabase(showData.java:45)
    at com.PNL.data.neo4j.showData.main(showData.java:34)
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.transaction.XaDataSourceManager@7594035c' 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)
    ... 6 more
Caused by: org.neo4j.kernel.lifecycle.LifecycleException: Component 'org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource@24367e26' 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)
    ... 8 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:124)
    at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.start(NeoStoreXaDataSource.java:323)
    at org.neo4j.kernel.lifecycle.LifeSupport$LifecycleInstance.start(LifeSupport.java:503)
    ... 11 more

顺便说一句:我的neo4j配置参数“allow_store_upgrade”也设置为“true”

任何帮助都将不胜感激

问候


共 (1) 个答案

  1. # 1 楼答案

    在您的代码中,配置不会被拾取。要更改此设置,请使用以下代码段初始化数据库:

    GraphDatabaseService graphDb = new GraphDatabaseFactory()
        .newEmbeddedDatabaseBuilder(Neo4J_DBPath)
        .loadPropertiesFromFile("confdir/neo4j.properties")
        .newGraphDatabase();
    

    确保neo4j.properties包含allow_store_upgrade=true。或者,您可以在工厂中使用不推荐的setConfig(name, value)