本文介绍了使用neo4j与jdk 1.7错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有neo4j-community-2.0-1.1的Java 1.7来构建一个示例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
* /

节点第一;
节点第二;
关系关系;
GraphDatabaseService graphDataService;

//关系列表
private static枚举RelationshipTypes实现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);

//开始事务
事务事务= graphDataService.beginTx();

try
{
//创建节点并设置属性节点
first = graphDataService.createNode();
first.setProperty(Name,Ravneet Kaur);

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

//指定关系

relation = first.createRelationshipTo(Second,RelationshipTypes.KNOWS);
relation.setProperty(relationship-type,知道);
// 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()
{
事务事务= graphDataService.beginTx();
try
{
first.getSingleRelationship(RelationshipTypes.KNOWS,Direction.OUTGOING).delete();
System.out.println(Nodes is deleted);
//删除节点
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中安装的JRE,执行环境和Java构建路径中进行了所有必要的更改,以指向最新的java。
现在我收到以下错误

 线程main中的异常java.lang.RuntimeException:启动org时出错。 neo4j.kernel.EmbeddedGraphDatabase,/Technology/neo4j-community-2.0-1.1 
在org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:330)
在org.neo4j.kernel.EmbeddedGraphDatabase。 < init>(EmbeddedGraphDatabase.java:63)
在org.neo4j.graphdb.factory.GraphDatabaseFactory $ 1.newDatabase(GraphDatabaseFactory.java:92)
在org.neo4j.graphdb.factory.GraphDatabaseBuilder。 newGraphDatabase(GraphDatabaseBuilder.java:198)
在org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:69)
在com.PNL.data.neo4j.showData.createDatabase(showData。 java:45)
at com.PNL.data.neo4j.showData.main(showData.java:34)
引起的:org.neo4j.kernel.lifecycle.LifecycleException:Component'org.neo4j。 kernel.impl.transaction.XaDataSourceManager@7594035c 已成功初始化,但未能启动。请参阅附件原因异常。
在org.neo4j.kernel.lifecycle.LifeSupport $ LifecycleInstance.start(LifeSupport.java:509)
在org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
在org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:307)
... 6更多
引起的:org.neo4j.kernel.lifecycle.LifecycleException:Component'org.neo4j .kernel.impl.nioneo.xa.NeoStoreXaDataSource @ 24367e26'已成功初始化,但无法启动。请参阅附件原因异常。
在org.neo4j.kernel.lifecycle.LifeSupport $ LifecycleInstance.start(LifeSupport.java:509)
在org.neo4j.kernel.lifecycle.LifeSupport.start(LifeSupport.java:115)
在org.neo4j.kernel.impl.transaction.XaDataSourceManager.start(XaDataSourceManager.java:164)
在org.neo4j.kernel.lifecycle.LifeSupport $ LifecycleInstance.start(LifeSupport.java:503)
... 8更多
导致:org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException:无法使用较旧的数据存储版本启动Neo4j。要启用自动升级,请在org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)$ org.neo4j.kernel
中设置配置参数allow_store_upgrade = true
。 impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:71)
在org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:144)
在org.neo4j。 kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:124)
在org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.start(NeoStoreXaDataSource.java:323)
在org.neo4j.kernel.lifecycle.LifeSupport $ LifecycleInstance.start(LifeSupport.java:503)
... 11更多

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



任何帮助将非常感谢。 >

关心

解方案

在您的代码的结构并不拾取。要更改此选项,请使用以下代码段来初始化您的数据库:

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

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


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

解决方案

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.

这篇关于使用neo4j与jdk 1.7错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 18:33