使用neo4j和jdk 1.7时出错

时间:2014-02-24 10:32:36

标签: java exception neo4j runtime

我正在使用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。所以我将其更改为JDK 1.7并在eclipse中对Installed JRE,Execution Environments和Java Build Path进行了所有必要的更改,以指向最新的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

BTW:我的neo4j配置参数“allow_store_upgrade”也设置为“true”。

任何帮助都将非常感激。

此致

1 个答案:

答案 0 :(得分:1)

在您的代码中,未获取配置。要更改此设置,请使用以下代码段初始化db:

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

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