Amr*_*esh 7 composite-key neo4j
我需要确保所有节点中多个属性值的组合是唯一的.如何在Neo4J中做到这一点.
从http://docs.neo4j.org/chunked/milestone/transactions-unique-nodes.html上提供的Neo4J文档中,可以确保一个属性的唯一性.但是2个或更多的组合怎么样?
你可以尝试
public Node getOrCreateUserWithUniqueFactory(final String firstName, final String lastname, GraphDatabaseService graphDb) {
UniqueFactory<Node> factory = new UniqueFactory.UniqueNodeFactory(graphDb, "users") {
@Override
protected void initialize(Node created, Map<String, Object> properties) {
created.setProperty("id", properties.get("id"));
created.setProperty("firstName", firstName);
created.setProperty("lastName", lastname);
}
};
return factory.getOrCreate("id", firstName + "_" + lastname);
}
Run Code Online (Sandbox Code Playgroud)