How to implement composite keys in Neo4J
I need to ensure that a combination of more than one property values in all nodes is unique. How to do that in Neo4J.
From Neo4J documentation available at http://docs.neo4j.org/chunked/milestone/transactions-unique-nodes.html, it's possible to ensure uniqueness of one property. But what about combination of 2 or more.
你可以试试
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);
}
链接地址: http://www.djcxy.com/p/69124.html
下一篇: 如何在Neo4J中实现组合键