How to implement composite keys in Neo4J

I need to make sure that the combination of several property values ​​in all nodes is unique. How to do it in Neo4J.

From the Neo4J documentation, available at http://docs.neo4j.org/chunked/milestone/transactions-unique-nodes.html , you can ensure that one property is unique. But what about a combination of two or more.

+7
source share
1 answer

You can try

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); } 
+4
source

All Articles