How do I register entity class as @Embedded ?

644 views
Skip to first unread message

Ed Gow

unread,
Dec 5, 2011, 9:58:24 PM12/5/11
to OrientDB
I'd like to store a class that contains a list of instances of another
class as a single JSON document using the ODatabaseObjectTx API. Is
this possible? How do I register the embedded class(s) so that they
will be stored that way?

I've tried registering only the top-level class and annotating the
contained class with @Embedded, but I get this error at runtime

14102 [main] ERROR orient.TestOrientDb$ - Caught exception
com.orientechnologies.orient.core.exception.OSerializationException:
Linked type [class test.Foo:test.Foo@549b6220] can't be serialized
because is not part of registered entities. To fix this error register
this class
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.typeToStream(OObjectSerializerHelper.java:
734)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.multiValueToStream(OObjectSerializerHelper.java:
810)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.typeToStream(OObjectSerializerHelper.java:
706)

Luca Garulli

unread,
Dec 5, 2011, 10:02:48 PM12/5/11
to orient-...@googlegroups.com
Hi,
first: what version are you using?
second: why don't register also the embedded class?

Lvc@

Ed Gow

unread,
Dec 6, 2011, 1:36:42 PM12/6/11
to OrientDB
I'm using 1.0rc6.

If I register the embedded class then it gets stored as separate
documents, by default in a separate cluster, that are referenced from
the containing document. That's not what I want. I want the contents
of both classes stored in a single document like this:


{
"bar": "bar value",
"foos": [
{ "foo1": "foo1 value" },
{ "foo2": "foo2 value" } ]
}

Since the underlying store of OrientDB is a document store, this is
how I understood it to work.

Luca Garulli

unread,
Dec 6, 2011, 2:37:17 PM12/6/11
to orient-...@googlegroups.com
Hi,
@Embedded tells to OrientDB to store the object inside the containing object as you want, while the registering of classes is to let OrientDB to inspect how classes are made.

So use @Embedded and register it too but I suggest you to use latest SVN trunk because has a fix on this.

Lvc@

Ed Gow

unread,
Dec 6, 2011, 8:58:01 PM12/6/11
to OrientDB
I'm trying 1.0rc8 SNAPSHOT from the svn. It still doesn't work. The
reason seems to be that the value of "EMBEDDED" in the schema property
interferes with my list being recognized as a list.

I get the exception

java.lang.IllegalArgumentException: Type EMBEDDED must be a multi
value type (collection or map)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.multiValueToStream(OObjectSerializerHelper.java:
812)

The value of iType at that point is the enum value EMBEDDED and the
name is "Embedded".

Is there anything I need to do to get my list recognized as such?

Luca Garulli

unread,
Dec 6, 2011, 9:51:49 PM12/6/11
to orient-...@googlegroups.com
Hi,
can you provide a tiny TestCase?

Lvc@

Ed Gow

unread,
Dec 8, 2011, 3:01:44 PM12/8/11
to OrientDB
I did a pure java test case and found that the JSON document is stored
just as I'd like it to be. My original problem was with a list class
that is a compatibility wrapper for Scala lists. When I did an
explicit copy from the Scala list into a Java ArrayList it started
working. The original wrapper class from Scala does implement
java.util.List, so I'm still puzzled about why OrientDB won't accept
it for storage.

Shang Cai

unread,
Dec 8, 2011, 5:59:27 PM12/8/11
to orient-...@googlegroups.com
If you are using immutable List, there's no explicit mutable and immutable collection in Java, When all collection.immutable.List gets translated into java.util.List, all mutable operations (i.e. add(e) yields UnsupportedOperationException). orientdb may be using some of those mutable methods.
--
/shang

Luca Garulli

unread,
Dec 8, 2011, 6:50:11 PM12/8/11
to orient-...@googlegroups.com
Hi,
unfortunately I don't know Scala, but by a double check into the code there is no "instanceof ArrayList" but all is based on List and sometime on Collection, so has to work.

And as answer to Shang during marshalling the collection is not touched, just browsed with the iterator or direct access via get().

What happens? Gives errors or the record is dirty? Please post some example to understand what could happen.

Lvc@
Reply all
Reply to author
Forward
0 new messages