Problems with object graph

94 views
Skip to first unread message

Stefan Ollinger

unread,
Jul 26, 2011, 6:49:24 PM7/26/11
to orient-...@googlegroups.com
Hello,

i try to save an object graph to the database. When reading the data
again from the database and traversing the graph, there are several
exceptions thrown. It would be great if someone could take a look at my
test case, and check if this is an error with my code or a bug:

https://github.com/dozed/orientdb-test/blob/master/src/test/java/org/noorg/orientdb/test/ObjectGraphDatabaseTest.java

Here the stracktraces:

1.)

2011-07-27 12:42:29:920 SEVE Fetching error on record #7:3
com.orientechnologies.orient.core.exception.ODatabaseException: Database
instance has been released to the pool. Get another database instance
from the pool with the right username and password
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTxPooled.checkOpeness(ODatabaseObjectTxPooled.java:100)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.existsUserObjectByRID(ODatabasePojoAbstract.java:317)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper$1.fetchLinked(OObjectSerializerHelper.java:347)
at
com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:105)
at
com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.fromStream(OObjectSerializerHelper.java:280)
at
com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.stream2pojo(ODatabaseObjectTx.java:418)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:358)
at
com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:331)
at
com.orientechnologies.orient.core.db.object.OLazyObjectIterator.next(OLazyObjectIterator.java:67)
at
com.orientechnologies.orient.core.db.object.OLazyObjectIterator.next(OLazyObjectIterator.java:54)
at
org.noorg.orientdb.test.ObjectGraphDatabaseTest.goDown(ObjectGraphDatabaseTest.java:37)
at
org.noorg.orientdb.test.ObjectGraphDatabaseTest.test(ObjectGraphDatabaseTest.java:32)

2.)

java.lang.ClassCastException:
com.orientechnologies.orient.core.record.impl.ODocument cannot be cast
to org.noorg.orientdb.test.domain.Page
at
org.noorg.orientdb.test.ObjectGraphDatabaseTest.goDown(ObjectGraphDatabaseTest.java:37)
at
org.noorg.orientdb.test.ObjectGraphDatabaseTest.goDown(ObjectGraphDatabaseTest.java:38)
at
org.noorg.orientdb.test.ObjectGraphDatabaseTest.test(ObjectGraphDatabaseTest.java:32)

Regards,
Stefan

Stefan Ollinger

unread,
Jul 27, 2011, 11:04:22 AM7/27/11
to orient-...@googlegroups.com
I am using 1.0rc4-snapshot btw.

Luca Garulli

unread,
Jul 27, 2011, 11:52:13 AM7/27/11
to orient-...@googlegroups.com
Hi,
seems that the page has subPage field loaded in lazy way and needs an open database to fetch them. You've some choices:
  • early load all the instances (just iterate the items)
  • by the same thread leave the db open
  • define a fetch-plan a load the entire object tree in one shoot and then work offline
Lvc@

Stefan Ollinger

unread,
Jul 27, 2011, 12:02:37 PM7/27/11
to orient-...@googlegroups.com

Luca Garulli

unread,
Jul 27, 2011, 12:37:22 PM7/27/11
to orient-...@googlegroups.com
There was a similar bug fixed some days ago. Probably the public snapshot was older. I've redeployed last SVN trunk.

Can you retry?

Lvc@

Stefan Ollinger

unread,
Jul 27, 2011, 1:31:58 PM7/27/11
to orient-...@googlegroups.com
It was me who reported that bug =)
I updated the snapshot on the project, but the test still fails.

Regards,
Stefan

Luca Garulli

unread,
Jul 29, 2011, 10:14:28 AM7/29/11
to orient-...@googlegroups.com
Hi,
I've fixed this stupid bug: I've just removed some checks if db is open on all the methods that don't require it. Dot.

SVN r3575.

Your test case pass, I've just run.

Lvc@

Stefan Ollinger

unread,
Jul 29, 2011, 1:27:35 PM7/29/11
to orient-...@googlegroups.com
Great, thanks again =)

Regards,
Stefan

Stefan Ollinger

unread,
Aug 1, 2011, 7:19:06 PM8/1/11
to orient-...@googlegroups.com
Hey Luca,

i modified the test case a bit. Now when saving the root entity first, then adding other sub entities and saving again the hierarchy wont be persisted correctly.

https://github.com/dozed/orientdb-test/blob/master/src/test/java/org/noorg/orientdb/test/ObjectGraphDatabaseTest.java

Could you take a look over it?

Regards,
Stefan

Luca Garulli

unread,
Aug 2, 2011, 10:21:08 AM8/2/11
to orient-...@googlegroups.com
Hi Stefan,
I've fixed this behaviour as SVN r3609. It was due to the internal serialization mechanism. Can you confirm it's fixed?

Lvc@

Stefan Ollinger

unread,
Aug 2, 2011, 1:22:25 PM8/2/11
to orient-...@googlegroups.com
Yes, works with latest trunk.

Stefan Ollinger

unread,
Aug 2, 2011, 3:04:07 PM8/2/11
to orient-...@googlegroups.com
Here is another test which produces some incorrect results:
https://github.com/dozed/orientdb-test/blob/master/src/test/java/org/noorg/orientdb/test/ObjectGraphDatabaseTest2.java

The pages seem to exist in the database, but only inside the container page. When requesting for all pages, only a subset of pages will be returned.

Regards,
Stefan

Luca Garulli

unread,
Aug 3, 2011, 1:36:14 AM8/3/11
to orient-...@googlegroups.com
Hi Stefan,
before I try this one could you update from SVN trunk and retry?

Lvc@

Stefan Ollinger

unread,
Aug 3, 2011, 7:43:45 AM8/3/11
to orient-...@googlegroups.com
There are still the same errors. Here are the stacktraces:

com.orientechnologies.orient.core.exception.OSerializationException: Linked type of field 'Page.parentPage' is unknown. Probably needs to be registered with <db>.getEntityManager().registerEntityClasses(<package>) or <db>.getEntityManager().registerEntityClass(<class>) or the package can't be loaded correctly due to a classpath problem. In this case register the single classes one by one.
    at com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper$1.fetchLinked(OObjectSerializerHelper.java:298)

    at com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:105)
    at com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.fromStream(OObjectSerializerHelper.java:280)
    at com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.stream2pojo(ODatabaseObjectTx.java:444)
    at com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:356)
    at com.orientechnologies.orient.core.db.ODatabasePojoAbstract.query(ODatabasePojoAbstract.java:226)
    at org.noorg.orientdb.test.Repository.findAll(Repository.java:26)
    at org.noorg.orientdb.test.ObjectGraphDatabaseTest2.testFindAll(ObjectGraphDatabaseTest2.java:42)

2011-08-03 01:42:03:808 SEVE Fetching error on record #7:2
com.orientechnologies.orient.core.exception.OSerializationException: Linked type of field 'Page.parentPage' is unknown. Probably needs to be registered with <db>.getEntityManager().registerEntityClasses(<package>) or <db>.getEntityManager().registerEntityClass(<class>) or the package can't be loaded correctly due to a classpath problem. In this case register the single classes one by one.
    at com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper$1.fetchLinked(OObjectSerializerHelper.java:298)

    at com.orientechnologies.orient.core.fetch.OFetchHelper.fetch(OFetchHelper.java:105)
    at com.orientechnologies.orient.core.serialization.serializer.object.OObjectSerializerHelper.fromStream(OObjectSerializerHelper.java:280)
    at com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.stream2pojo(ODatabaseObjectTx.java:444)
    at com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:356)
    at com.orientechnologies.orient.core.db.ODatabasePojoAbstract.query(ODatabasePojoAbstract.java:226)
    at org.noorg.orientdb.test.Repository.findAll(Repository.java:26)
    at org.noorg.orientdb.test.ObjectGraphDatabaseTest2.testFindAll(ObjectGraphDatabaseTest2.java:42)


junit.framework.AssertionFailedError: expected:<5> but was:<2>
    at junit.framework.Assert.fail(Assert.java:47)

Regards,
Stefan

Luca Garulli

unread,
Aug 3, 2011, 12:47:03 PM8/3/11
to orient-...@googlegroups.com
Hi Stefan,
ObjectGraphDatabaseTest test passes for you (with latest SVN, not Maven repository)?

Lvc@

Stefan Ollinger

unread,
Aug 3, 2011, 6:58:27 PM8/3/11
to orient-...@googlegroups.com

Luca Garulli

unread,
Aug 4, 2011, 6:52:19 AM8/4/11
to orient-...@googlegroups.com
Hi Stefan,
fixed in SVN r3624. Please tell me if now works at 100%.

Lvc@

Stefan Ollinger

unread,
Aug 4, 2011, 7:04:39 AM8/4/11
to orient-...@googlegroups.com
Hi Luca,
the test passes now. Thanks =)

Regards,
Stefan

Stefan Ollinger

unread,
Aug 4, 2011, 7:24:19 AM8/4/11
to orient-...@googlegroups.com
Hey,
there seems to another bug which creates duplicate records inside the db. Check out this test case:
https://github.com/dozed/orientdb-test/blob/master/src/test/java/org/noorg/orientdb/test/ObjectGraphDatabaseNestedTest.java

junit.framework.AssertionFailedError: expected:<5> but was:<9>
    at junit.framework.Assert.fail(Assert.java:47)
    at junit.framework.Assert.failNotEquals(Assert.java:283)
    at junit.framework.Assert.assertEquals(Assert.java:64)
    at junit.framework.Assert.assertEquals(Assert.java:195)
    at junit.framework.Assert.assertEquals(Assert.java:201)
    at org.noorg.orientdb.test.ObjectGraphDatabaseNestedTest.testFindAll(ObjectGraphDatabaseNestedTest.java:58)

Any ideas?

Regards,
Stefan

Stefan Ollinger

unread,
Aug 4, 2011, 5:39:52 PM8/4/11
to orient-...@googlegroups.com
Just fixed the assertion, there should be really 6 instead 5 elements in the db. But the test still fails.

Luca Garulli

unread,
Aug 4, 2011, 6:26:14 PM8/4/11
to orient-...@googlegroups.com
Hi,
fixed also this one: SVN r3628.

Lvc@

Stefan Ollinger

unread,
Aug 4, 2011, 7:48:09 PM8/4/11
to orient-...@googlegroups.com
Works like a charm =)

Adolfo Rodriguez

unread,
Aug 4, 2011, 7:57:30 PM8/4/11
to orient-...@googlegroups.com
Hi all,
 
I have a question related to version attribute. I want to use the version attribute to version my ODocuments. I had some similar requirement in my business model and I want to try to reuse the one provided by OrientDB.
 
My ODocuments are linked through edges to other ODocuments of different Class.
I have noticed that version attribute increases whenever a new edge is attached to the ODocument.
However, in my business logic, only links to ODocuments of some specific class(es) should increase version value, but not all new edges.
 
* Is there any way where I can customize what 'events' should increase version value and what not?? (e.g. a 'version' change listener passing the event)
* If not, does it make sense enough in your use cases to be added as enhancement?
 
Thanks,
 
Adolfo
 
PD: Sorry if my address sends any spam . It looks that my Yahoo online account has been hacked today.

Adolfo Rodriguez

unread,
Aug 5, 2011, 10:08:40 AM8/5/11
to OrientDB
Hi all,

I have a question related to version attribute. I want to use the version attribute to version my ODocuments. I had some similar requirement in my business model and I want to try to reuse the one provided by OrientDB.

My ODocuments are linked through edges to other ODocuments of different Class.
I have noticed that version attribute increases whenever a new edge is attached to the ODocument.
However, in my business logic, only links to ODocumentsof some specific class(es) should increase version value, but not all new edges.

Luca Garulli

unread,
Aug 5, 2011, 10:13:57 AM8/5/11
to orient-...@googlegroups.com
Hi Adolfo,
internal version is incremented every time the record is updated, so you can't control it. The best is to create a your "version" field with your logic.

Lvc@

pellyadolfo

unread,
Aug 5, 2011, 10:17:07 AM8/5/11
to OrientDB
Thanks Luca, probably is used for internal management or something
like that, I guess.... Maybe a line in wiki would prevent further
similar questions.

Good to know,

Adolfo

On Aug 5, 4:13 pm, Luca Garulli <l.garu...@gmail.com> wrote:
> Hi Adolfo,
> internal version is incremented every time the record is updated, so you
> can't control it. The best is to create a your "version" field with your
> logic.
>
> Lvc@
>

Stefan Ollinger

unread,
Aug 6, 2011, 5:48:00 AM8/6/11
to orient-...@googlegroups.com
Hey,

I am trying to move an instance from a parent to a new parent.

Here is the database content:

Page(id=0, title=root, parentPage=null)
--Page(id=1, title=foo, parentPage=0)
--Page(id=2, title=bar, parentPage=0)
--Page(id=3, title=baz, parentPage=0)
----Page(id=4, title=nested, parentPage=3)

That is the new content after moving "foo" from "root" to "nested":

Page(id=0, title=root, parentPage=null)
--Page(id=1, title=foo, parentPage=4)
--Page(id=2, title=bar, parentPage=0)
--Page(id=3, title=baz, parentPage=0)
----Page(id=4, title=nested, parentPage=3)
------Page(id=1, title=foo, parentPage=4)

The database doesnt seem to reflect the removal of the instance from the parent.

Test case is here: https://github.com/dozed/orientdb-test/blob/master/src/test/java/org/noorg/orientdb/test/RewiringTest.java

Regards,
Stefan



Am 05.08.2011 00:26, schrieb Luca Garulli:

Luca Garulli

unread,
Aug 6, 2011, 10:54:00 AM8/6/11
to orient-...@googlegroups.com
Hi Stefan,
your test case fetch the collection when the database is closed. I've added a check for this, so now your test case fails but with an exception.

You've to redesign your test cases to have a living database instance when operate on lazy collections or traverse all the tree to be sure all is loaded before to close.

Lvc@

Stefan Ollinger

unread,
Aug 6, 2011, 3:41:11 PM8/6/11
to orient-...@googlegroups.com
Hi Luca,

should that really throw an exception? I mean i loaded the tree with a fetchPlan *:-1. So i expect that i can traverse freely over the object tree.

Regards,
Stefan

Luca Garulli

unread,
Aug 6, 2011, 7:43:06 PM8/6/11
to orient-...@googlegroups.com
The fetch plan *:-1 (seems a sort of smile!) tells to pre-load all the connected object into the client cache but the collection are all lazy, so the real unmarshalling into the POJO happens on first access.

This is what happens today. A lot of users asked a way to avoid this behaviour and effectively seems constraining. For this reason I've open this issue to pre-fetch objects following the fetch plan:


In the meanwhile you can detach manually the result set with:

db.detach(pojo).

Available since SVN r3631.

Lvc@

PS: Attached your test case with detaching
LazyLoadingDatabaseTest.java
Reply all
Reply to author
Forward
0 new messages