Java OrientDB:事务处于活动状态时无法更改架构。架构更改不是事务性的
我目前正在嵌入式模式下使用Java Graph API评估OrientDB,以供将来的项目使用。在分布式设置中使用事务图实现时,我注意到以下问题:Java OrientDB:事务处于活动状态时无法更改架构。架构更改不是事务性的,java,transactions,orientdb,Java,Transactions,Orientdb,我目前正在嵌入式模式下使用Java Graph API评估OrientDB,以供将来的项目使用。在分布式设置中使用事务图实现时,我注意到以下问题: 在服务器启动和激活之后,我通过OrientGraphFactory::factory.getTx()获得一个图形实例 在第一个节点上,我设置了一个简单的模式,如下所示: graph.getRawGraph().commit(); if (graph.getVertexType("Person") == null) graph.createV
graph.getRawGraph().commit();
if (graph.getVertexType("Person") == null)
graph.createVertexType("Person");
final OrientVertexType vtPerson = graph.getVertexType("Person");
if (vtPerson.getProperty("firstName") == null)
vtPerson.createProperty("firstName", OType.STRING);
if (vtPerson.getProperty("lastName") == null)
vtPerson.createProperty("lastName", OType.STRING);
vtPerson.createEdgeProperty(Direction.OUT, "lives");
vtPerson.createEdgeProperty(Direction.OUT, "history");
vtPerson.setStrictMode(true);
try {
final OrientVertex person = graph.addVertex("class:Person", "firstName", firstName, "lastName", lastName);
graph.getRawGraph().commit();
return person;
} catch (Exception e) {
e.printStackTrace();
graph.rollback();
}
com.orientechnologies.orient.core.exception.OSchemaException: Cannot change the schema while a transaction is active. Schema changes are not transactional
DB name="test"
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.saveInternal(OSchemaShared.java:1284)
at com.orientechnologies.orient.core.metadata.schema.OSchemaShared.releaseSchemaWriteLock(OSchemaShared.java:606)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.releaseSchemaWriteLock(OClassImpl.java:2028)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.releaseSchemaWriteLock(OClassImpl.java:2023)
at com.orientechnologies.orient.core.metadata.schema.OClassImpl.setClusterSelectionInternal(OClassImpl.java:2062)
at com.orientechnologies.orient.server.distributed.impl.ODistributedAbstractPlugin.propagateSchemaChanges(ODistributedAbstractPlugin.java:1439)
at com.orientechnologies.orient.server.distributed.impl.ODistributedStorage.checkForCluster(ODistributedStorage.java:1803)
at com.orientechnologies.orient.server.distributed.impl.ODistributedTransactionManager.checkForClusterIds(ODistributedTransactionManager.java:275)
at com.orientechnologies.orient.server.distributed.impl.ODistributedTransactionManager.commit(ODistributedTransactionManager.java:87)
at com.orientechnologies.orient.server.distributed.impl.ODistributedStorage.commit(ODistributedStorage.java:1240)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.doCommit(OTransactionOptimistic.java:569)
at com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:109)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2667)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:2637)
当使用OrientGraphNoTx实现时,一切都按预期工作。但是,我更喜欢使用事务图,以便能够回滚事务。这是正确的-Orient中的模式更改不是事务性的。您应该使用非事务性操作来创建或修改架构,使用事务性操作来对图形进行数据更改
如果需要将架构更改作为业务逻辑的一部分来执行,请先运行它们,如果它们失败,也请使数据事务失败。需要注意的是,在某些情况下,如果您使用事务上下文执行架构更改,OrientDB将以静默方式提交正在进行的事务,因此请确保您从不这样做。这是正确的-Orient中的架构更改不是事务性的。您应该使用非事务性操作来创建或修改架构,使用事务性操作来对图形进行数据更改
如果需要将架构更改作为业务逻辑的一部分来执行,请先运行它们,如果它们失败,也请使数据事务失败。需要注意的是,在某些情况下,如果您使用事务上下文执行架构更改,OrientDB将以静默方式提交正在进行的事务,因此请确保您从不这样做。
添加新顶点时,我在何处执行架构更改?
模式更改在此if
块中完成createVertexType(“Person”)
更改架构
if (graph.getVertexType("Person") == null)
graph.createVertexType("Person");
正如您所提到的,当您使用callfactory.getTx()
时,您正在使用一个事务
OrientGraphFactory::factory.getTx()
相反,试试看
graph = new OrientGraphNoTx("your URL");
请点击这里:
添加新顶点时,我到底在哪里执行架构更改?
模式更改在此if
块中完成createVertexType(“Person”)
更改架构
if (graph.getVertexType("Person") == null)
graph.createVertexType("Person");
正如您所提到的,当您使用callfactory.getTx()
时,您正在使用一个事务
OrientGraphFactory::factory.getTx()
相反,试试看
graph = new OrientGraphNoTx("your URL");
请点击这里:
它告诉您模式更改不是事务性的。数据更改是事务性的。它告诉您模式更改不是事务性的。数据更改是。添加新顶点时,我在哪里执行模式更改?此外,我已经尝试使用一个非事务性图来初始设置模式,然后使用事务性图来添加顶点。但在添加多个顶点后,我得到了相同的异常。当添加新顶点时,我到底在哪里执行模式更改?此外,我已经尝试使用一个非事务性图来初始设置模式,然后使用事务性图来添加顶点。但是在添加多个顶点之后,我得到了相同的异常。