Orientdb: Create new Graph database

2019-06-23 22:49发布

问题:

I'm trying to create a new instance of OrientGraph database, as follows:

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

anyhow, while sticking with the manual and do it with ODatabaseDocumentTx like:

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

then I want to get a session like:

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

}
finally
{
    g.shutdown();
}

I got the following exception:

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

How Can I create a new graph database???

Thank you.

回答1:

First, you should not use the "local" engine anymore, it is deprecated (your first example). Secondly, the way an OrientGraph must be created is clearly documented, see http://www.orientechnologies.com/docs/last/orientdb.wiki/Graph-Factory.html

The complete example which should work:

@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();
    }
}

Finally, your reported error indicates a set of inconsistent jar files. You should:

  • use Java 6+ (for version < 2.x) or 7+ (for version >= 2.x, this is not documented)
  • use the jars mentioned here: http://www.orientechnologies.com/docs/last/orientdb.wiki/Graph-Database-Tinkerpop.html from OrientDB (OrientDB uses a modified tinkerpop implementation). Best is to use maven :)

Needed dependencies:

- 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

UPDATE:

For a complete example, see https://github.com/rmuller/graphdb-playground (under 'orientdb-embedded-graph')



回答2:

After a wild struggling with V2 I went back to V.1.7.9 and everything works.

Maven Dependency: com.orientechnologies orientdb-graphdb 1.7.9

it seems that there are some unsolved issues with V.2.x I will do another PoC within a month or so.