cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Recycled ids using UuidStrategy

kev_0126
Node Link

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 !

1 ACCEPTED SOLUTION

MuddyBootsCode
Graph Steward

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.

View solution in original post

4 REPLIES 4

MuddyBootsCode
Graph Steward

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.

Thanks for your answer, but you mention

If you're also using something like uuid or RandomUUID you're going to be fine.

Does it mean if I use only

@NodeEntity
public class Actor {

    @Id
    @GeneratedValue(strategy = UuidStrategy.class)
    private UUID id;
}

i am guaranteed that the id (which is a uuid in fact) will never be recycled upon deletion ?

Thanks for your precision.

MuddyBootsCode
Graph Steward

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.

Ok, now I got the subtle difference between the assigned _id and my own id property.
Thanks for the clarification, marking your answer as solution !