Spring Data Neo4j主键

时间:2014-06-25 22:52:02

标签: neo4j spring-data-neo4j

我是Neo4j和SDN的新手。我试图使用@Indexed(unique = true)为我的实体创建主键。它创建了唯一的节点,但如果我使用了索引的相同属性值,它将替换其他属性。 例如:

Class abc{
@Indexed(unique=true)
Long abc_id;
String abc_name;
}

new abc(1,"asd")// creates node with id: 1 name : asd
new abc(1,"xyz")// replaces asd with xyz . 

但是我想抛出关于主键冲突/重复节点的异常。

是否有一些方法可以达到同样的效果?

1 个答案:

答案 0 :(得分:2)

目前@Indexed实现不会对spring数据neo4j论坛上的这个JIRA票证中引用的任何重复项引发任何异常:here以及此thread

您可以创建运行密码查询的唯一节点(速度更快)。您可以使用MERGE创建或更新节点。

来自文档

MERGE either matches existing nodes and binds them, or it creates new data and binds that. It’s like a combination of MATCH and CREATE that additionally allows you to specify what happens if the data was matched or created.

如果您想要更新任何节点或创建一个节点(如果该模式不存在),那么您可以执行以下操作。

MERGE (keanu:Person { name:'Keanu Reeves' })
ON CREATE SET keanu.created = timestamp()
ON MATCH SET keanu.lastSeen = timestamp()
RETURN keanu
相关问题