Lazy Loading of Links

If I have a Country document that has a linklist to City documents which in turn has a linklist to People documents and I load a specific Country document using the record ID, when our the linklists of City documents and their linklists to the People documents loaded into memory? Is this explained in the documentation somewhere? If so, could someone point me to that section. If not, could someone explain how links and lazy loading works using the Java Multi-Mode API?


Hi @mwarble

By default OrientDB loads linked documents lazily, so when you load a document, it only loads the RIDs of the connected documents. As soon as you access the single property (eg. a link or linklist property), the connected references are automatically loaded from the database, so you don’t have to do the load manually.

This applies to the Multi-Model API, with a single exception, that is SQL and result sets. In SQL you have two peculiar behaviors:

OResult item =
item.getProperty("aLinkProperty");  // this returns a RID
item.getElementProperty("aLinkProperty"); //this loads and returns the linked OElement
item.getVertexProperty("aLinkProperty"); //this loads and returns the linked OVertex, null if it's not a vertex
item.getEdgeProperty("aLinkProperty"); //this loads and returns the linked OEdge, null if it's not an edge

I hope it helps