Create schema for graph database with Java in OrientDB

六眼飞鱼酱① 提交于 2019-12-06 13:36:08

问题


I'm trying to create schema for graph database in OrientDB with Java but I have two problems I can't solve. I'm using this example http://orientdb.com/docs/last/Graph-Schema.html

  1. When I use this code
OServerAdmin serverAdmin = new OServerAdmin("remote:localhost").connect("root", "1234");
serverAdmin.createDatabase("mydb", "graph", "plocal");
serverAdmin.close();

I get the following error:

java.lang.NoSuchMethodError: com.orientechnologies.common.concur.resource.OResourcePool.getAllResources()Ljava/util/Collection; at com.orientechnologies.orient.client.r

It creates the database but nothing more, because I get that exception.

  1. I can create the database from the command line instead and then create the schema with Java like:
OrientGraph graph = new OrientGraph("remote:localhost/mydb", "root", "1234");         
OrientVertexType userVType = graph.createVertexType("User");
userVType.createProperty("email", OType.STRING)
// ...

It works fine but it will try to create the schema every time I run the program and I got the error messages like the user class already exist etc. So I wonder how could I check if the database and the schema already exist or which is the right way to create schema with Java in OrientDB?


回答1:


See here there I show a complete example about creating a graph database.

Some of the main points about that import:

  • use always the factory factoryGraph = new OrientGraphFactory(dbPath, "admin", "admin").setupPool(1, 10);
  • create database structure with the non-graph environment (somehow this works much better I found out after some time) db = new ODatabaseDocumentTx(dbPath);
  • create helper methods (e.g. void createProperty(String className, String propertyName, OType oType) {...})

I'm working with this way of import in my latest project and having no issues. I also created a technique to save the old functions and after the import I restore them.

If you need more infos let me know and I'll add them here.



来源:https://stackoverflow.com/questions/30143462/create-schema-for-graph-database-with-java-in-orientdb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!