Accessing OrientDB 1.7-RC1 from Scala, when attempting to save an ODocument with an embeddedset of objects of a custom type, I get an exception saying that the corresponding field is of an incompatible type. I need help in figuring out what I'm doing wrong.
The code to create/save the ODocument looks as follows, it represents a Package which has an embeddedset of Dependency objects:
val myHashSet = new util.HashSet[models.Dependency]()
myHashSet.add(new models.Dependency("mydep", "1.0"))
val myVersion = new ODocument("Version")
.field("id", "myversion")
.field("dependencies", myHashSet)
myVersion.save()
This leads to the following exception being thrown:
com.orientechnologies.orient.core.exception.OValidationException: The field 'Version.dependencies' has been declared as EMBEDDEDSET but an incompatible type is used. Value: Dependency(mydep,1.0)
at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.validateEmbedded(ORecordSchemaAwareAbstract.java:429) ~[orientdb-core-1.7-rc1.jar:1.7-rc1]
at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.validateField(ORecordSchemaAwareAbstract.java:249) ~[orientdb-core-1.7-rc1.jar:1.7-rc1]
at com.orientechnologies.orient.core.record.ORecordSchemaAwareAbstract.validate(ORecordSchemaAwareAbstract.java:71) ~[orientdb-core-1.7-rc1.jar:1.7-rc1]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1357) ~[orientdb-core-1.7-rc1.jar:1.7-rc1]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1347) ~[orientdb-core-1.7-rc1.jar:1.7-rc1]
at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1336) ~[orientdb-core-1.7-rc1.jar:1.7-rc1]
I've declared the Version.dependencies embeddedset in the database's schema like this:
create property Version.dependencies embeddedset Dependency
The Dependency class definition looks as follows (it implements OSerializableStream since this is supposedly necessary for serializing embedded objects):
case class Dependency(var id: String, var specifier: String) extends OSerializableStream {
def this() = this(null, null)
override def toStream: Array[Byte] = {
val bytes: Array[Byte] = Json.prettyPrint(Json.toJson(this)).getBytes
bytes
}
override def fromStream(iStream: Array[Byte]): OSerializableStream = {
val json = Json.parse(iStream)
val dependency = Json.fromJson[Dependency](json).get
dependency
}
}
object Dependency {
implicit val versionFormat = Json.format[Dependency]
}
What am I doing wrong here?