Have a question regarding inheritance model implementation in OrientDB

34 views
Skip to first unread message

Varun Tahin

unread,
Aug 4, 2016, 2:25:41 AM8/4/16
to OrientDB
I have a graph created in which i want to impose an inheritance model .
As a sample code I am defining superclass and subclass doing somewhat like this:

OrientGraph graph = new OrientGraph("remote:/localhost/newhilti", "root", "varun");
graph.createVertexType("Mysubclass", "Person");

in this I have already made a Person class(superclass for Mysubclass) which is containing some properties and I am defining  some other distinct properties for Mysubclass too like this:

Vertex vPerson = graph.addVertex("class:Mysubclass");
vPerson.setProperty("firstName", "John");
vPerson.setProperty("lastName", "Smith");
graph.commit();

Now I cannot see the properties which are in Person class when I query Mysubclass. Are they not inherited properly or I am missing some link . Please suggest.

Thanks-
Varun Tahin

odbuser

unread,
Aug 4, 2016, 3:31:46 AM8/4/16
to OrientDB
The following will show Vertices from Mysubclass only:
select from Mysubclass

The following will show Vertices from Person and all subclasses of Mysubclass.
select from Person

In either query result, you will see all of the properties of each vertex.  Class inheritance will inherit defined properties but it doesn't sound like you have actually defined any properties (just added property values to vertices).

For this you need to use the "create property" SQL command.  You can execute it from the Java API but there isn't a method in the API such as graph.createProperty(String vclass,String propertyName, etc.).  See the following for more details:
http://orientdb.com/docs/last/SQL-Create-Property.html
Reply all
Reply to author
Forward
0 new messages