So I found out eventually that I need to put ODocument instances in embeddedsets. I wish this were documented!
On Sun, Mar 23, 2014 at 10:11 PM, Arve Knudsen <[email protected]>wrote: > After declaring the embeddedset property explicitly in the database schema > ('create property Version.dependencies embeddedset Dependency'), it looks > like it goes wrong already at creation. I now get this exception when > saving the ODocument: > > 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] > > > The creation code that causes this exception looks as follows: > > 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() > > The Dependency class looks like this (with a companion object for JSON > formatting): > > 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?? See also my > SO<http://stackoverflow.com/questions/22597119/why-cant-i-save-this-odocument-with-embeddedset-property-to-orientdb>question > on this issue. > > Thanks, > Arve > > > On Sat, Mar 22, 2014 at 11:49 PM, Arve Knudsen <[email protected]>wrote: > >> Hi guys >> >> With OrientDB 1.7-rc1, I can't for the life of me figure out how to load >> an >> embeddedset<https://github.com/orientechnologies/orientdb/wiki/Concepts#1-n-and-n-m-embedded-relationships>from >> an ODocument in Scala, even though I think i have stored the set >> correctly. I stored objects implementing OSerializableStream in a HashSet >> with the ODocument, and it looks alright when doing SQL selects on the >> embeddedset. However, when I load the set back from the ODocument, it's >> represented as a collection of strings, i.e. there's no deserialization. >> >> What I've tried is basically this, given that version is an ODocument and >> the type contained in the embeddedset ("dependencies") is Dependency: >> >> val deps = >> version.field[OTrackedList[Dependency]]("dependencies").asScala.toSeq >> val dep: Dependency = deps.head >> >> The final statement throws this exception: *[ClassCastException: >> java.lang.String cannot be cast to models.Dependency]*. How can I read >> the "dependencies" field properly deserialized to a Set[Dependency]?? >> Please help! >> >> Thanks, >> Arve >> > > -- --- You received this message because you are subscribed to the Google Groups "OrientDB" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
