The Scope of a Transaction
fppt opened this issue · comments
Hi,
I am a bit confused with regards to how orient is handling the tx()
method. Specifically, if I do the following:
OrientGraphFactory factory = new OrientGraphFactory("memory:myGraph");
OrientGraph graph = factory.getNoTx();
graph.createVertexClass("TYPE");
graph.createVertexClass("ANOTHER_TYPE");
graph.commit();
graph = factory.getNoTx();
graph.addVertex("TYPE");
graph.commit();
graph.addVertex("ANOTHER_TYPE");
graph.commit();
Everything appears to work. If I change the second graph = factory.getNoTx();
to graph = factory.getTx();
, then it fails.
Similarly if I make the 2nd to last commit graph.tx().commit();
it fails again. In all cases it fails with this error:
Caused by: com.orientechnologies.orient.core.exception.OSchemaException: Cannot change the schema while a transaction is active. Schema changes are not transactional
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.saveInternal(OSchemaShared.java:1202)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.releaseSchemaWriteLock(OSchemaShared.java:634)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.releaseSchemaWriteLock(OSchemaShared.java:623)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.doCreateClass(OSchemaShared.java:1045)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:407)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.createClass(OSchemaShared.java:392)
at com.orientechnologies.orient.core.metadata.schema.OSchemaProxy.createClass(OSchemaProxy.java:100)
at org.apache.tinkerpop.gremlin.orientdb.OrientGraph.createClass(OrientGraph.java:552)
... 37 more
Also it looks like the tx()
method is creating a new transaction. Is this really the case ? For my implementation I need to use the Tinkerpop defined graph.tx().commit()
I can't use the orient specific graph.commit()
.
In essence I would like to be able to do
graph = factory.create();
//Add some vertices and edges
graph.tx().commit();
//Add some more vertices and edges
graph.tx().commit();
Is there anyway to achieve this sort of behaviour using orientdb ?
hmm, this sounds like a bug. maybe it's related with the automated prefixing of the class name, i.e. V_ and E_? see https://github.com/mpollmeier/orientdb-gremlin#labels-and-classes
Can you check the names of the created classes in the two cases addVertex
and createVertexClass
?
Hi mpollmeier,
I think it is a bug because when I watch the following classes:
graph.database.browseClass("TYPE")
graph.database.browseClass("V_TYPE")
they both throw exceptions initially, but after createVertexClass
"TYPE" is valid and after addVertex
"V_TYPE" is valid. So it appears addVertex
appends the V
and createVertexClass
does not.
For fun I tried to "fix" this issue: #89 . Apologies if I am way off base. I thought it might be a good way to get more into the code.
Fixed with the referenced PR.