The following issue arises using 1.7.3.
The following code works as expected in a db from memory. However, it does
not work on a remote database. If you run the following code you will view
the expected output, but if you use a remote db the link from tyrion to
jamie will appear correct within the ODocument but will not be saved
properly to the database. I would best describe this as a nested link to a
document.
The code actually throws an exception from a remote db even though it runs
without issue from memory. Please find the code below.
import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.tx.OTransaction.TXTYPE;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import com.orientechnologies.orient.core.db.record.OIdentifiable;
class innerDoc {
public static void main(String[] args) {
/*
ODatabaseDocumentTx db = new ODatabaseDocumentTx(
"remote:localhost/orientjson");
db.open("admin", "admin");
*/
ODatabaseDocumentTx db = new ODatabaseDocumentTx("memory:test");
db.create();
ODocument jaimeDoc = new ODocument("PersonTest");
jaimeDoc.field("name", "jaime");
jaimeDoc.save();
ODocument cerseiDoc = new ODocument("PersonTest");
cerseiDoc.fromJSON("{\"@type\":\"d\",\"name\":\"cersei\",\"lover\":"
+ jaimeDoc.toJSON() + "}");
cerseiDoc.save();
// The link between jamie and tyrion is not saved properly
ODocument tyrionDoc = new ODocument("PersonTest");
tyrionDoc
.fromJSON("{\"@type\":\"d\",\"name\":\"tyrion\",\"emergency_contact\":{\"relationship\":\"brother\",\"contact\":"
+ jaimeDoc.toJSON() + "}}");
tyrionDoc.save();
System.out.println("The saved documents are:");
for (ODocument o : db.browseClass("PersonTest")) {
System.out.println("my id is " + o.getIdentity().toString());
System.out.println("my name is: " + o.field("name"));
System.out.println("my ODocument representation is " + o);
System.out.println("my JSON representation is " + o.toJSON());
System.out.println("my traversable links are: ");
for (OIdentifiable id : new OSQLSynchQuery<ODocument>(
"traverse * from " + o.getIdentity().toString())) {
System.out.println(db.load(id.getIdentity()).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.