Temporary vertices are persisted by graph without saving
OrientDB Version, operating system, or hardware.
- v2.2.9
Operating System
- [ ] Linux
- [ ] MacOSX
- [x] Windows
- [ ] Other Unix
- [ ] Other, name?
Expected behavior and actual behavior
I'm using vertices provided by graph.addTemporaryVertex as beans for my view.
A input form is automatically created from the schema information.
The problem arises with multiple views opened concurrently.
By vertex.save()ing and graph.commit()ing the temp vertices in one view the other temp vertices are persisted too without vertex.save()ing them.
See the following test case. Can someone point me into the right direction how to avoid this problem?
Steps to reproduce the problem
@Test
public void testDontCommitUnsavedTempVertex()
{
OrientGraph graph = factory.getTx();
// User opens 2 editors concurrently
// Editor 1
OrientVertex v1a = graph.addTemporaryVertex( "TestV" );
OrientVertex v1b = graph.addTemporaryVertex( "TestV" );
// Editor 2
OrientVertex v2 = graph.addTemporaryVertex( "TestV" );
// User fills some data
// Editor 1
v1a.setProperty( "a1", "b1" );
v1b.setProperty( "a2", "b2" );
v1a.addEdge( "TestE", v1b );
// Editor 2
v2.setProperty( "a3", "b3" );
// User saves only editor 1
v1a.save();
v1b.save();
graph.commit();
Assert.assertTrue( v1a.getIdentity().isPersistent() );
Assert.assertTrue( v1b.getIdentity().isPersistent() );
Assert.assertTrue( v2.getIdentity().isPersistent() == false ); // ASSERTION FAILED
// User now saves editor 2
v2.save();
graph.commit();
Assert.assertTrue( v2.getIdentity().isPersistent() );
}
The moment you call v2.setProperty( "a3", "b3" );, the vertex is added to the transaction. The only way to bypass this is to set properties with: v2.getDocument().field("a3", "b3").
Hi @lvca , thanks for the answer. I wrote a wrapper class to delegate some of the calls to OrientVertex.iRawElement instead of using the calls with save() in them. Why is the save()ing all the time the desired behaviour and are there any repercussions of my workaround?
TinkerPop standard requires an automatic save. If you work with the underlying document and then you remember to save, it's fine.