0

我无法在 Neo4j 的嵌入式 Java 版本中访问以前创建的数据库。我想做的是打开一个 GraphDatabaseService,添加几百万个关系(不使用 BatchInserter,只使用事务),然后关闭最后一个事务和连接。这看起来像:

public class startNeo4j{ …
  public static void main (String[] args) {
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "data/test/base" );
    Transaction tx = graphDb.beginTx();
    IndexManager index = graphDb.index();
    Index<Node> userIds = index.forNodes("userIds");
    RelationshipIndex follows = index.forRelationships("follows");

[在这里我输入了一个非常大的 csv(数百万关系),还给出了关系和 userId 索引]

    tx.finish();
    graphDb.shutdown(); }}

然后我需要做的是打开一个新的 GraphDatabaseService 并访问我刚刚插入的所有数据。我查看了 Neo4j 列表,他们确认这是可能的,但没有提供任何细节。

我不想重新创建索引,但是当我尝试简单地重新打开它时,我收到一个错误,即索引(来自上面的 userIds)“无法解析”。理想情况下,如果有人对第二组代码的外观有一个大纲,那就太好了。我的非功能性的看起来像:

public class examineNeo4j{
  public static void main (String[] args){
    GraphDatabaseService graphDb = new EmbeddedGraphDatabase( "data/test/base" );
    Transaction tx = graphDb.beginTx();
    IndexHits<Node> hits_final = userIds.get("userId","12");
    Node testthis = hits_final.getSingle();

[或我想运行的其他查询]

    tx.finish();
    graphDb.shutdown();}}

任何帮助将不胜感激!

4

1 回答 1

1

您还必须执行 tx.success(); 默认情况下,tx 处于“回滚”状态。

Transaction tx = graphDb.beginTx();
try {
  // do your work here
  tx.success();
} finally {
  tx.finish();
}
graphdb.shutdown();

另请记住,您的 tx 大小不应超过 10k 操作。所以请以这样的块大小批量交易。

于 2011-07-10T23:46:27.670 回答