Error using neo4j with jdk 1.7

2019-08-21 19:56发布

I am using Java 1.7 with neo4j-community-2.0-1.1 to build a sample neo4j graph database. Please see below my code

 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");
}

}

Earlier I was using Jave 1.6 to compile this code, but got to know that this neo4j jar complies with jdk 1.7. So I changed it to JDK 1.7 and made all necessary changes in Installed JRE, Execution Environments and Java Build Path in eclipse to point to latest java. Now I get the following error

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: Also my neo4j configuration parameter "allow_store_upgrade" is set to "true".

Any help will be really appreciated.

Regards

1条回答
一夜七次
2楼-- · 2019-08-21 20:47

In your code the configuration is not picked up. To change this use the following snippet to initialize your db:

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

Make sure neo4j.properties contains allow_store_upgrade=true. Alternatively you can use the deprecated setConfig(name, value) on the factory.

查看更多
登录 后发表回答