Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to generatej uuid in java for neo4j nodes

Tags:

java

neo4j

Neo4j does not recommend to use node id to store in third party system for later referencing.

  1. So what is best ways to generate uuid in java for neo4j nodes?
  2. Currently I'm using UUID.randomUUID(); to generate uuid. Is there any performance impact for neo4j search if I use UUID.randomUUID()?
like image 716
Prabudda Sri Rahal Avatar asked Dec 19 '22 11:12

Prabudda Sri Rahal


2 Answers

Now Cypher has a randomUUID native function, see https://neo4j.com/docs/cypher-manual/current/functions/scalar/

like image 117
JohnSmith Avatar answered Jan 19 '23 00:01

JohnSmith


It is true that you should not reference an internal id in an external system as internal ids are not stable.

One option for generating a UUID would be using the apoc.create.uuid function available in the apoc procedure library. For example:

CREATE (p:Person)
SET p.name = "Bob",
    p.uuid = apoc.create.uuid()

See this blog post for more information on user defined procedures and functions.

like image 30
William Lyon Avatar answered Jan 19 '23 00:01

William Lyon