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

Temporary ID in different transactions #154

Open
To-om opened this issue Aug 21, 2018 · 3 comments
Open

Temporary ID in different transactions #154

To-om opened this issue Aug 21, 2018 · 3 comments
Assignees
Labels

Comments

@To-om
Copy link

To-om commented Aug 21, 2018

When a create a vertex, I get a temporary ID (ends with ":-2"). I can retrieve that vertex
with the string representation of the ID only in the same transaction.
If I open a new transaction, the ID is unusable

OrientGraph graph1 = factory.getTx();
Vertex v = graph1.addVertex(labelVertex);
String vid = v.id().toString();
Assert.assertEquals(1, graph1.V(vid).toList().size()); // succeeds
graph1.tx().commit();

OrientGraph graph2 = factory.getTx();
Assert.assertEquals(1, graph2.V(vid).toList().size()); // fails

String newId = vid.substring(0, vid.length() - 2) + "0";
Assert.assertEquals(1, graph2.V(vid).toList().size()); // succeeds
graph2.tx().commit();

I suppose replacing ":-2" by ":0" is not the solution.
How can I provide a stable ID to client (I am in a web application context) ?

@wolf4ood
Copy link
Member

Hi @To-om

OrientDB uses temporary rids in transactions and are resolved at commit time.
That means that if you store a termporary rids in a String you will get the temporary rid.

if you change the code in this way it works

OrientGraphFactory factory = new OrientGraphFactory("plocal:/tmp/test");

    OrientGraph graph1 = factory.getTx();
    String labelVertex = "Test";
    Vertex v = graph1.addVertex(labelVertex);
    Assert.assertEquals(1, graph1.traversal().V(v.id()).toList().size()); // succeeds
    graph1.tx().commit();
    String vid = v.id().toString();

    OrientGraph graph2 = factory.getTx();
    Assert.assertEquals(1, graph2.traversal().V(vid).toList().size()); // fails

    String newId = vid.substring(0, vid.length() - 2) + "0";
    Assert.assertEquals(1, graph1.traversal().V(vid).toList().size()); // succeeds
    graph2.tx().commit();

@wolf4ood wolf4ood self-assigned this Aug 27, 2018
@To-om
Copy link
Author

To-om commented Aug 30, 2018

Thank you for your answer.
In my case, transaction encompasses the whole HTTP request process, including the build of the response.
I think that it is not a good idea to commit the transaction before each id obtained because the process could fail after that, rollback won't be possible.

@wolf4ood
Copy link
Member

@To-om

the idea is to keep all the newly created vertices edges and then after commit use the api

v.id() 

to get the persisted record id

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants