1

I know how to create an Record with the Web GUI of OrientDB. How am I able to create a New Record with the Java API? This is what I have done with the GUI so far.

You can download the full version of the picture here

enter image description here

This is my code so far but my knowledge is to low. I just know how to handle Vertex.

    OrientGraphFactory ogf = new OrientGraphFactory(
            "plocal:/home/paulkalkbrenner/Dokumente/odb/databases/ConnectER", "admin", "admin");
    OrientGraph og = ogf.getTx();

    try {
        System.out.println("message bevor vertex");

        Vertex relation0_vertex = og.addVertex(null);
        relation0_vertex.setProperty("Lastname", rel0);

        //System.out.println("Features = " + og.getFeatures());
        for (Vertex v : og.getVertices()) {
            System.out.println(v.getProperty("Lastname"));
        }
    }
    finally {
        og.shutdown();
    }

1 Answer 1

2

try this code

OrientGraphFactory ogf = new OrientGraphFactory(
        "plocal:/home/paulkalkbrenner/Dokumente/odb/databases/ConnectER", "admin", "admin");
    OrientGraph og = ogf.getTx();

    OClass cl=og.createVertexType("Person", "V");
    cl.createProperty("LastName", OType.STRING);

    OrientVertex v1=og.addVertex("class:Person");
    v1.setProperties("Lastname","Alessandro");

    for (Vertex v : og.getVertices()) {
        System.out.println(v.getProperty("Lastname"));
    }

    og.shutdown();
Sign up to request clarification or add additional context in comments.

4 Comments

you mean the setProperties creates a new Record?
with OrientVertex v1=og.addVertex("class:Person") the new vertex of type Person is created and with v1.setProperties("Lastname","Alessandro") is set the property Lastname
so you mean when I create a new Record with the GUI and put in Alessandro, it is the same as setProperties("Lastname","Alessandro") ?
when you create a new Record with the GUI and put in Alessandro ,it is the same as og.addVertex("class:Person").setProperties("Lastname","Alessandro");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.