Cannot create mandatory Edge property without validation causing an exception

Hello Community!

I’ve recently encountered an issue that is putting me in a bit of an annoying dilemma. My current setup is using an embedded OrientDB instance within my Kotlin code. The issue I am having is when attempting to create multiple new vertices interconnected with Edge classes, as opposed to using lightweight edges. I’ve read all of the documentation I can find, but am still stuck at receiving this same stacktrace message, as found here:

Caused by: com.orientechnologies.orient.core.exception.OValidationException: The field 
'xxx.xxx' is mandatory, but not found on record: xxx DB name="xxx"

As is now obvious, the issue arises when using a LINK datatype on a Vertex property. If the property is marked as being mandatory, then it becomes impossible to create the Vertex alongside the mandatory property, because of how the back-end code handles transactions.

Doing my research, I have tried the following solutions:

  1. Using detach() and attach(...) on all of the Vertices.
  2. Using OrientGraphNoTx.
  3. Using Vertex.addEdge(...) and OrientGraph/NoTx.addEdge(...).
  4. Using TemporaryVertex instances, rather than the ‘live’ version.

But none of these solutions have worked. Looking through the source code being called behind these methods, it is apparent that:

  1. Many of the internal methods are, as expected, private/hidden, so it is not possible to easily create my own Edge instance, bypassing the usage of transactions.
  2. Any method(s) used to create an Edge instance result in the call of the doc.validate() method, which checks that the given structure of Vertices and Edges matches the stated schema.

This last point is essential to why I believe this issue exists; every time a TemporaryVertex is modified, it is not validated until it is saved. However, due to there being no temporary edges, their schema is validated every single time they are modified. Given that an Edge must be connected to two vertices, the vertices are also included in that validation check. When attempting to create a structure comprised of multiple vertices and edges intertwined, especially when one vertex has multiple mandatory edge properties, it is impossible to circumvent or pause the checking process.

I cannot find a solution around this, the current fix I have in place is to just simply set all mandatory edge properties to false before the vertex it applies to is serialised in to the database schema. This obviously isn’t a great solution, as it effectively disables usage of a whole database feature and can lead to some unnecessary faults in db contents. If there is a solution available, I would be very grateful to hear it. If not, my suggestion is to add the feature of temporary edges, created the same way that temporary vertices are created. Looking through the source code, I don’t imagine this would be too difficult as it can likely be made from modifying a copy of the TemporaryVertex code. Either that, or a means of manually disabling/enable pre-commit validation. I am also unable to use the one-liner parameter setup solution, as I need access to the inputted variables later in my code.

All and any help is appreciated. Many thanks!

Hi @JD202

which version are you using of OrientDB?

Hey @wolf4ood,

I am using OrientDB-server version 3.0.30 and OrientDB-graphdb version 3.0.30.

@JD202

did you consider using the MultiModel APIs?

The orientdb-graph are the old api based on TP2, they are kind of deprecated in favor of the multimodel one.

Thanks