warning: this project is pretty much outdated, I suggest to use the well maintained https://github.com/graphaware/neo4j-uuid instead.
A lot of Neo4j based projects I've seen need a unique identifier for nodes/relationship to reference contents in the graph database from some third party system. The most obvious thing namely using node.getId() is a bad choice since after deletion of a node its id might be recycled. For details on why and how this works, see an excellect blog post. A best practice for having unique identifiers is to assign each node/relationship a uuid property and let Neo4j perform autoindexing on the uuid property. Third party systems store only the UUID. A simple index lookup retrieves then the referenced node or relationship in the graph database.
build & install
neo4j-uuid uses Gradle as build system. To install uuid-neo4j in a Neo4j server instance:
./build/libs/neo4j-uuid.jarto your Neo4j server's
copy the latest version of http://mvnrepository.com/artifact/com.fasterxml.uuid/java-uuid-generator to Neo4j's
pluginsdirectory as well (will automate that step in future).
$NEO4J_SERVER/conf/neo4j-server.propertieswith the following line:
- for testing Spock is used
- Neo4j scans using JDK ServiceLoader for registered implementations of KernelExtensionFactory. We register UUIDKernelExtensionFactory that passes back an instance of UUIDLifeCycle. UUIDLifeCycle takes care of setting up auto indexing for
uuidproperties and registers a
- a second component provides a unmanaged extension for querying nodes/rels by uuid, see