Neo4 Java更新节点上的所有属性,包括唯一约束属性

时间:2020-07-10 09:15:21

标签: java neo4j

我目前正在使用neo4j 3.5社区版嵌入式数据库,并且对Identifier属性有独特的约束。

我正在通过做交易

Map<String, Object> properties = // Map of new properties
GraphDatabaseService service = ...
try (Transaction tx = service.beginTx()) {
    // Consider the node is existing
    Node node = service.findNode(label, "Identifier", identifier);
    // Replace the properties on the node including identifier
    neoEntity.getPropertyKeys().forEach(neoEntity::removeProperty);
    graphEntity.getProperties().forEach(neoEntity::setProperty);
    neoEntity.setProperty(IDENTIFIER, graphEntity.getIdentifier());

    tx.success();
}

如果仅执行此操作,则其行为就像更新属性一样。 但是,如果我在同一事务service.findNodes(label, "Identifier", identifier).stream().toArray()中使用相同的标识符再次查询;我得到两个具有相同nodeId和相同属性(包括标识符)的实体。 我必须查询节点,因为某些关系是通过仅知道两端的标识符来创建/更新的,而这是在同一事务循环中发生的。我想避免将所有修改后的节点保留在变量中,以防它们在关系中使用。

我猜想它会在事务结束时合并,因为我在另一个事务中再次查询它时,它只会返回一个。

所以我的问题是更新属性时我做错了什么?

谢谢您的回答:)

0 个答案:

没有答案
相关问题