Hi,
I am wondering if node ID defined using UUID strategy might be recycled. Neo4j doc clearly states that one should not rely on the internally generated node ID as Neo4J might reuse it when deleting node, but doc is quite vague about the UUID strategy.
Do not rely on this ID for long running applications. Neo4j will reuse deleted node ID’s. It is recommended users come up with their own unique identifier for their domain objects (or use a UUID).
Now, suppose the following code:
@NodeEntity
public class Actor {
@Id
@GeneratedValue(strategy = UuidStrategy.class)
private UUID id;
}
With above definition, if Actor node is deleted, will the ID be recycled or not ?
Thanks a lot !
The ID that's being referred to in the documentation is the _id that Neo4j assigns to a node on creation. If you're also using something like uuid or RandomUUID you're going to be fine.
The issues with ID's being recycled or changed if you move your graph to another Neo4j instance or upgrade your current instance comes from the auto assigned ID that Neo4j gives to every node on creation. So let say that you create this actor node, internally Neo4j is going to give it whatever properties that you assign to it, as well as a generated _id property in your case say:
CREATE (n:Actor) set n.id = randomUUID(), name = "Keanu" return n
In addition to the properties that you applied to the node, you'll have the previously mentioned _id so in this return you'd get:
Actor {
id: the random UUID created (which in perfect world will always be unique)
name: Keanu
_id: 1
}
The id property that has the possibility of being duplicated or recycled is the _id property, not the UUID or whatever other ID you give the node. I hope that clears it up.