orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Setting field of ODocument after commit/close fails with OrientGraph

Open Vannav opened this issue 11 years ago • 1 comments

I have problems with switching from ODatabaseDocumentTx to OrientGraph. I'm mainly working on ODocuments in a thread where ODatabaseRecordThreadLocal is not set. After finishing the modification to the document I save & commit to database. Working with OrientGraph throws an exception in the modification step. My current workaround is setting ODocument#setDirty() after the commit (before passing it to a non-DB thread). Here's an example:

ODatabaseDocumentTx db = new ODatabaseDocumentTx(
      "remote:localhost/..." ).open( "admin", "admin" );

// Fails if I use an OrientGraph; Comment this line out and no exception are thrown
OrientGraph graph = new OrientGraph( db );

// Get some document
ODocument doc = null;
for( ODocument idoc : db.browseClass( "MyVertex" ) )
{
   doc = idoc;
}

// Modify a property field
doc.field( "name", "test" );

// Save modification and commit
doc.save();
db.commit();

// WORKAROUND: Set dirty after commit to avoid serialization problem with next field modification
//doc.setDirty();

db.close();

// THROWS EXCEPTION
doc.field( "name", "test2" ); 
Nov 13, 2015 10:39:37 AM com.orientechnologies.common.log.OLogManager log
WARNUNG: Error deserializing record with id #13:52 send this data for debugging: ABZMYWJFaW5oZWl0VgEAAAAnHGluX0xhYkVpbmhlaXRFAAAALBYACHRlc3QDzyxyUiqFQQSJYVslDxHWYgAAAAEADgAAAAAAAACnAAAAAAAAAAAAAA== 
Exception in thread "main" com.orientechnologies.orient.core.exception.ODatabaseException: Database instance is not set in current thread. Assure to set it with: ODatabaseRecordThreadLocal.INSTANCE.set(db);
    at com.orientechnologies.orient.core.db.ODatabaseRecordThreadLocal.get(ODatabaseRecordThreadLocal.java:51)
    at com.orientechnologies.orient.core.record.ORecordAbstract.getDatabase(ORecordAbstract.java:240)
    at com.orientechnologies.orient.core.record.impl.ODocument.getGlobalPropertyById(ODocument.java:2147)
    at com.orientechnologies.orient.core.record.impl.ODocumentInternal.getGlobalPropertyById(ODocumentInternal.java:60)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.getGlobalProperty(ORecordSerializerBinaryV0.java:280)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.deserialize(ORecordSerializerBinaryV0.java:179)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.fromStream(ORecordSerializerBinary.java:74)
    at com.orientechnologies.orient.core.record.impl.ODocument.deserializeFields(ODocument.java:1817)
    at com.orientechnologies.orient.core.record.impl.ODocument.checkForFields(ODocument.java:2405)
    at com.orientechnologies.orient.core.record.impl.ODocument.field(ODocument.java:1035)
    at com.orientechnologies.orient.core.record.impl.ODocument.field(ODocument.java:884)

Vannav avatar Nov 13 '15 10:11 Vannav

Hi,

You can use an ODocument out of the database context only if you detach it, calling "doc.detach()" before close the database.

tglman avatar May 09 '16 12:05 tglman