Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link to ODocument saved properly and later corrupted [related to #2411] #2660

Closed
idpspace opened this issue Aug 8, 2014 · 2 comments
Closed
Assignees
Milestone

Comments

@idpspace
Copy link

idpspace commented Aug 8, 2014

When laa worked on #2411, he was under the impression that my JSON was incorrect. However, it was my intent to leave out a document type because the emergency contact is not meant to be a document but a field of a document that includes a "link" to a second document. It appears that in OrientDB 1.7.7, the nested link is initially stored properly and later corrupted by subsequent db activity.

I have provided code below that illustrates my issue. Initially, the nested link to a document is saved properly, however, the query returns a corrupted version of the document. The corrupted version no longer includes the link but has some but not all of the values of the document having the rid. Most importantly, the rid value has disappeared.

import com.orientechnologies.orient.core.record.impl.ODocument;
import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery;
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
import java.util.List;

class InnerDoc {

public static void main(String[] args) {

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

    ODocument jaimeDoc = new ODocument("PersonTest");
    jaimeDoc.field("name", "jaime");
    jaimeDoc.save();

    ODocument tyrionDoc = new ODocument("PersonTest");
    tyrionDoc
            .fromJSON("{\"@type\":\"d\",\"name\":\"tyrion\",\"emergency_contact\":[{\"relationship\":\"brother\",\"contact\":"
                    + jaimeDoc.toJSON() + "}]}");
    tyrionDoc.save();

    System.out.println(db.load(tyrionDoc.getIdentity()).toJSON());

    List<ODocument> result = db.query(
              new OSQLSynchQuery<ODocument>("select from " + tyrionDoc.getIdentity()));

    System.out.println(result.get(0).toJSON());

    db.close();

}

}

@idpspace idpspace changed the title closed issue #2411 [a nested link to a document] link to ODocument saved properly and later corrupted [related to #2411] Aug 9, 2014
@idpspace
Copy link
Author

FYI. The issue does not occur with a DB from memory.

@tjackson1982
Copy link

Just wanted to add to this bug, to help identify the core issue.

Just a warning - I am no expert of Orient, but I was debugging to help out. I am not sure what is known, and may not use the proper terminology, but I think I can show that the server is definitely corrupted on the return after the query.

With the Code provided by the OP, the "data" is misrepresented only after the OSQLSynchQuery, and then continues to be incorrect, thus "corrupted".

so above, the DB load will return the objects with the proper rids

System.out.println(db.load(tyrionDoc.getIdentity()).toJSON());

"emergency_contact":[{"relationship":"brother","contact":"#11:112"}]}

However after the SQL Query (and other database commands).

List<ODocument> result = db.query(
          new OSQLSynchQuery<ODocument>("select from " + tyrionDoc.getIdentity()));

the output is then - the inner #11:112 is lost.

"emergency_contact":[{"relationship":"brother","contact":{"@type":"d","@Version":0,"@Class":"PersonTest","name":"jaime"}}]}

Now at first I thought it was just a marshalling issue, but a DB load AFTER the SQL call will now return the same thing as the query. The DB Load _has changed_.

So... I started to debug the query code which brought me to OChannelBinaryProtocol, line 124.

  final ORecordId rid = network.readRID();
  final ORecordVersion version = network.readVersion();
  final byte[] content = network.readBytes();
  record.fill(rid, version, content, false);

the "network" is where the retrieved record comes back from the server in byte code. Line at record.fill is where the returned record of "tyrion" is filled in, including our "emergencyContact". Unfortunately by that time, the our "inner" object rid is lost.

emergency_contact:[{"relationship":"brother","contact":(PersonTest@name:"jaime")}]

@andrii0lomakin andrii0lomakin added this to the 1.7.9 milestone Aug 29, 2014
@andrii0lomakin andrii0lomakin self-assigned this Sep 2, 2014
@andrii0lomakin andrii0lomakin modified the milestones: 2.0rc1, 1.7.9 Sep 2, 2014
@tglman tglman assigned tglman and unassigned andrii0lomakin Sep 10, 2014
@tglman tglman closed this as completed Sep 15, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants