问题
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
- 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.
- 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