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:
attach(...)on all of the Vertices.
TemporaryVertexinstances, 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:
- Many of the internal methods are, as expected, private/hidden, so it is not possible to easily create my own
Edgeinstance, bypassing the usage of transactions.
- Any method(s) used to create an
Edgeinstance 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!