Hi,

I am trying to use Orient Transactions and I am running into issues.  I 
have provided a test case below.  The code and example below may seem 
arbitrary but it is a part of a scala DAO implementation that includes 
transactions. 

I am trying to:
1) start a transaction
2) create a first and second ODocument
3) store the temporary RID value of the first ODocument in a "nested" field 
of the second ODocument
4) commit the transaction and have the temporary RID stored in the second 
ODocument updated to the final RID value 

In the example below.. 
there is a Person Class and an Event Class. Event Class has an "admin" 
field that is collection of a wrapper class for RIDs. The example below 
displays that when the RID is inside of the wrapper class it will not be 
updated to reflect the commit.

import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.storage.OStorage;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.id.ORID;
import com.orientechnologies.orient.core.metadata.schema.OClass;

import java.util.List;
import java.util.ArrayList;

class Main{ 


  public static void main (String [] args) { 

      ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test");
      db.create(); 
      
      OClass person = db.getMetadata().getSchema().createClass("Person");
      OClass event = db.getMetadata().getSchema().createClass("Event");
      OClass eventjson = 
db.getMetadata().getSchema().createClass("Event_JSON");
      
      db.begin( TXTYPE.OPTIMISTIC );
      ODocument doc = new ODocument("Person"); 
      doc.field("name","Sunil");
      doc.save();
      ORID adminID = doc.getIdentity();
      List<ORID> adminList = new ArrayList<ORID>();
      adminList.add(adminID);
      
      ODocument doc2 = new ODocument("Event"); 
      doc2.field("event_name","world cup 2014").field("admin",adminList);
      doc2.save();
      
      ODocument doc3 = new ODocument("Event_JSON");
      doc3.fromJSON("{\"event_name\":\"world cup 
2018\",\"admin\":[{\"typehint\":\"oID\",\"id\":\""+ adminID + "\"}]}");
      doc3.save();
      
      db.commit();
      
      for (ODocument o : db.browseClass("Event")) {
          System.out.println(o.toJSON());
      }
      
      for (ODocument o : db.browseClass("Person")) {
          System.out.println(o.toJSON());
      }
      
      //Output will include the temp id and not the id assigned after the 
transaction is committed
      for (ODocument o : db.browseClass("Event_JSON")) {
          System.out.println(o.toJSON());
      }
      
      db. close ( ) ; 
  }  
}

-- 

--- 
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.

Reply via email to