Orientdb graph database storing objects in vertices

428 views
Skip to first unread message

nandan parikh

unread,
Jun 5, 2015, 10:10:14 AM6/5/15
to orient-...@googlegroups.com
When i store objects in vertices and then try to add edges between those vertices I get the error - Impossible serialize value of type class

alessand...@gmail.com

unread,
Jun 5, 2015, 10:16:14 AM6/5/15
to orient-...@googlegroups.com
Hi,
can you post your code ?

Regards,
Alessandro 
Message has been deleted

nandan parikh

unread,
Jun 6, 2015, 1:32:08 PM6/6/15
to orient-...@googlegroups.com
I need to add the whole 'data' in one property of a vertex. is this not possible at all?      


 OrientGraph graph = new OrientGraph("memory:test");
       
        Data data = new Data();
        data.addData("a","b","c");

        Vertex first = graph.addVertex(null);
        first.setProperty("name","anything");
        first.setProperty("DATA", data);
       
        Vertex second = graph.addVertex(null);
        second.setProperty( "name", "Marko" );
       
       
        Edge lucaKnowsMarko = graph.addEdge(null, first, second, "relation");



Shows this error ::
Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException: Impossible serialize value of type class odb.Data with the ODocument binary serializer
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.serialize(ORecordSerializerBinaryV0.java:257)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.toStream(ORecordSerializerBinary.java:104)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:2105)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:714)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commitEntry(OAbstractPaginatedStorage.java:1939)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commit(OAbstractPaginatedStorage.java:922)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:488)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:147)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2427)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2397)
    at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.executeOutsideTx(OrientBaseGraph.java:1705)
    at com.tinkerpop.blueprints.impls.orient.OrientElement.checkForClassInSchema(OrientElement.java:617)
    at com.tinkerpop.blueprints.impls.orient.OrientEdge.getClassName(OrientEdge.java:531)
    at com.tinkerpop.blueprints.impls.orient.OrientEdge.createDocument(OrientEdge.java:568)
    at com.tinkerpop.blueprints.impls.orient.OrientEdge.<init>(OrientEdge.java:76)
    at com.tinkerpop.blueprints.impls.orient.OrientVertex.addEdge(OrientVertex.java:935)
    at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addEdge(OrientBaseGraph.java:685)
    at odb.vertex1.main(vertex1.java:25)

nandan parikh

unread,
Jun 6, 2015, 1:59:42 PM6/6/15
to orient-...@googlegroups.com
I am using the latest version of OrientDB. My only doubt is if I can add Object in any property of a vertex!
Here the object is data which has some of its own properties.

On Friday, 5 June 2015 19:46:14 UTC+5:30, alessand...@gmail.com wrote:

alessand...@gmail.com

unread,
Jun 8, 2015, 4:04:18 AM6/8/15
to orient-...@googlegroups.com
Hi,
   class Data must implement Serializable and provide for this class get method.

   Try this code 
   first.setProperty("name","anything");
   first.setProperty("DATA", data.getList());

   Regards,
   Alessandro



Message has been deleted

nandan parikh

unread,
Jun 8, 2015, 5:48:47 AM6/8/15
to orient-...@googlegroups.com
Thanks!
Now I want to add a JSON Object to the vertex.

I tried using :
   JSONObject json = new JSONObject(); 
 
  Vertex first = graph.addVertex(null);
       json.put("data","anything);
        first.setProperty("allprop",json);
It shows the same serialization error :
    How to add implements serializable to JSON???

Error is :
Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException: Impossible serialize value of type class org.json.JSONObject with the ODocument binary serializer

    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.serialize(ORecordSerializerBinaryV0.java:257)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.toStream(ORecordSerializerBinary.java:104)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:2105)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:714)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.executeSaveRecord(ODatabaseDocumentTx.java:1687)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.addRecord(OTransactionOptimistic.java:312)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.saveRecord(OTransactionOptimistic.java:253)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:2306)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.save(ODatabaseDocumentTx.java:118)
    at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1734)
    at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:1725)
    at com.orientechnologies.orient.core.record.impl.ODocument.save(ODocument.java:98)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.recursiveLinkSave(ORecordSerializerBinaryV0.java:674)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.writeOptimizedLink(ORecordSerializerBinaryV0.java:688)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.writeSingleValue(ORecordSerializerBinaryV0.java:572)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.serialize(ORecordSerializerBinaryV0.java:261)

    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.toStream(ORecordSerializerBinary.java:104)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:2105)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:714)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commitEntry(OAbstractPaginatedStorage.java:1939)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commit(OAbstractPaginatedStorage.java:922)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:488)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:147)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2427)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2397)
    at com.tinkerpop.blueprints.impls.orient.OrientTransactionalGraph.commit(OrientTransactionalGraph.java:162)
    at odb.vedge.main(vedge.java:39)

alessand...@gmail.com

unread,
Jun 8, 2015, 6:22:57 AM6/8/15
to orient-...@googlegroups.com
Hi,
   try this code

   Data data = new Data();
   data.addData("a","b","c");
    
   Gson gson = new Gson();
   String json = gson.toJson(data);

   Vertex first = graph.addVertex(null);
   first.setProperty("name","anything");
   first.setProperty("allprop",json.toString()); 

  Regards,
  Alessandro

nandan parikh

unread,
Jun 8, 2015, 6:35:59 AM6/8/15
to orient-...@googlegroups.com
converting to string works for all objects.

Is there any way we can store the json object without converting to toString() ???

alessand...@gmail.com

unread,
Jun 8, 2015, 8:59:15 AM6/8/15
to orient-...@googlegroups.com
Hi,
i have tried this code and it seems to work

OrientGraph graph = new OrientGraph("memory:test");
    
     Data data = new Data();
     data.setNome("New Data");
     data.addData("a","b","c");
    
     JSONObject json=new JSONObject();
     json.put("data", data);
     
     Vertex first = graph.addVertex(null);
     first.setProperty("name","anything");
     first.setProperty("allprop",json);
     
     Vertex second = graph.addVertex(null);
     second.setProperty( "name", "Marko" );
     
     Edge lucaKnowsMarko = graph.addEdge(null, first, second, "relation");

Bye, Alessandro.

nandan parikh

unread,
Jun 8, 2015, 9:08:33 AM6/8/15
to orient-...@googlegroups.com
Copy pasted your code and I get this error
Exception in thread "main" com.orientechnologies.orient.core.exception.OSerializationException: Impossible serialize value of type class org.json.JSONObject with the ODocument binary serializer
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinaryV0.serialize(ORecordSerializerBinaryV0.java:257)
    at com.orientechnologies.orient.core.serialization.serializer.record.binary.ORecordSerializerBinary.toStream(ORecordSerializerBinary.java:104)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:2105)
    at com.orientechnologies.orient.core.record.impl.ODocument.toStream(ODocument.java:714)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commitEntry(OAbstractPaginatedStorage.java:1939)
    at com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage.commit(OAbstractPaginatedStorage.java:922)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:488)
    at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:147)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2427)
    at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2397)
    at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.executeOutsideTx(OrientBaseGraph.java:1705)
    at com.tinkerpop.blueprints.impls.orient.OrientElement.checkForClassInSchema(OrientElement.java:617)
    at com.tinkerpop.blueprints.impls.orient.OrientEdge.getClassName(OrientEdge.java:531)
    at com.tinkerpop.blueprints.impls.orient.OrientEdge.createDocument(OrientEdge.java:568)
    at com.tinkerpop.blueprints.impls.orient.OrientEdge.<init>(OrientEdge.java:76)
    at com.tinkerpop.blueprints.impls.orient.OrientVertex.addEdge(OrientVertex.java:935)
    at com.tinkerpop.blueprints.impls.orient.OrientBaseGraph.addEdge(OrientBaseGraph.java:685)
    at odb.vedge.main(vedge.java:35)
Jun 08, 2015 6:36:30 PM com.orientechnologies.common.log.OLogManager log
INFO: - closing storage: tinkerpop...

alessand...@gmail.com

unread,
Jun 8, 2015, 11:00:43 AM6/8/15
to orient-...@googlegroups.com
Hi,
I have created a small example with the class Data and the class Test
Let me know if it works.

Alessandro

Data.java
Test.java

nandan parikh

unread,
Jun 12, 2015, 6:31:42 AM6/12/15
to orient-...@googlegroups.com
Though it did not work, I figured out the solution.
Serialization error will go only if the Json Object is converted to Json string before storing, and then retrieving the Json string and converting back to Json obejct.

Thanks anyways.
Cheers.
Reply all
Reply to author
Forward
0 new messages