【问题标题】:Orientdb: Create new Graph databaseOrientdb:创建新的图形数据库
【发布时间】:2023-10-08 01:51:01
【问题描述】:

我正在尝试创建一个新的 OrientGraph 数据库实例,如下:

OrientGraph graph = new OrientGraph("local:C:/temp/graph/db");
graph.create(); //BUT no create method!!

无论如何,在坚持使用手册的同时,使用 ODatabaseDocumentTx 进行操作,例如:

db = new ODatabaseDocumentTx("plocal:c:/orientdb/db");
db.create();
....
db.shutdown();

然后我想要一个像这样的会话:

OrientGraphFactory factory = new OrientGraphFactory("plocal:c:/orientdb/db", "admin", "admin");
OrientGraphNoTx g = factory.getNoTx();
try
{

}
finally
{
    g.shutdown();
}

我遇到了以下异常:

java.lang.IncompatibleClassChangeError: Expected static method     com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.checkForGraphSchema(Lcom/orientechnologies/orient/core/db/document/ODatabaseDocumentTx;)

如何创建新的图形数据库???

谢谢。

【问题讨论】:

    标签: java orientdb tinkerpop


    【解决方案1】:

    首先,您不应再使用“本地”引擎,它已被弃用(您的第一个示例)。其次,必须明确记录创建 OrientGraph 的方式,请参阅http://www.orientechnologies.com/docs/last/orientdb.wiki/Graph-Factory.html

    应该工作的完整示例:

    @Test
    public void testNoTx() {
        // start with a non existing database
        final OrientGraphFactory factory = new OrientGraphFactory(
            "plocal:" + DB_DIR, "admin", "admin");
        assertFalse(factory.exists());        
        try {
            OrientGraphNoTx g = factory.getNoTx();
            // database is auto created
            assertFalse(g.isClosed());
            assertFalse(g.isRequireTransaction());
        } finally {
            // this also closes the OrientGraph instances created by the factory
            // Note that OrientGraphFactory does not implement Closeable
            factory.close();
        }
    }
    

    最后,您报告的错误表明一组不一致的 jar 文件。你应该:

    需要的依赖:

    - com.orientechnologies:orientdb-graphdb:jar:2.0-M2:compile
      +- com.orientechnologies:orientdb-core:jar:2.0-M2:compile
      |  +- org.xerial.snappy:snappy-java:jar:1.1.0.1:compile
      |  +- com.googlecode.concurrentlinkedhashmap:concurrentlinkedhashmap-  lru:jar:1.4:compile
      |  +- net.java.dev.jna:jna:jar:4.0.0:compile
      |  \- net.java.dev.jna:jna-platform:jar:4.0.0:compile
      \- com.tinkerpop.blueprints:blueprints-core:jar:2.6.0:compile
         +- com.fasterxml.jackson.core:jackson-databind:jar:2.2.3:compile
         |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.2.3:compile
         |  \- com.fasterxml.jackson.core:jackson-core:jar:2.2.3:compile
         +- com.carrotsearch:hppc:jar:0.6.0:compile
         \- commons-configuration:commons-configuration:jar:1.6:compile
            +- commons-collections:commons-collections:jar:3.2.1:compile
            +- commons-lang:commons-lang:jar:2.4:compile
            +- commons-digester:commons-digester:jar:1.8:compile
            |  \- commons-beanutils:commons-beanutils:jar:1.7.0:compile
            \- commons-beanutils:commons-beanutils-core:jar:1.8.0:compile
    

    更新:

    有关完整示例,请参阅https://github.com/rmuller/graphdb-playground(在“orientdb-embedded-graph”下)

    【讨论】:

    • 也许我对 orientdb 不走运,让我再试一次……我完全按照你的代码(没有断言)做了,我得到:'java.lang.NoSuchFieldError:supportsThreadIsolatedTransactions'在 Java 1.7 上编译,具有以下 Maven 依赖项:orient-commons 2.0-M1 orientdb-core 2.0-M2 blueprints-core 2.5.0 orientdb-graphdb 2.0-M2 任何想法!
    • 好的,这很清楚。您的依赖项不一致,请参阅我的更新答案。我假设当 OrientDB 是最终版本时,他们将提供 orientdb-graph-all.jar 或类似的东西。目前,如果不使用 maven,您必须自己收集这些文件。但是,它确实应该可以正常工作,没有问题!
    【解决方案2】:

    在与 V2 的激烈斗争之后,我回到了 V.1.7.9,一切正常。

    Maven 依赖: com.orienttechnologies orientdb-graphdb 1.7.9

    V.2.x 似乎有一些未解决的问题,我将在一个月左右的时间内再做一次 PoC。

    【讨论】:

    • 查看我的更新答案,其中包含指向完整“准备运行”示例的链接。你应该让它在 5 分钟内运行 :)