orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Temporary vertices are persisted by graph without saving

Open Vannav opened this issue 10 years ago • 3 comments

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() );
   }

Vannav avatar Sep 30 '16 14:09 Vannav

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

lvca avatar Sep 30 '16 20:09 lvca

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?

Vannav avatar Oct 01 '16 20:10 Vannav

TinkerPop standard requires an automatic save. If you work with the underlying document and then you remember to save, it's fine.

lvca avatar Oct 02 '16 08:10 lvca