Search code examples
neo4jcypherspring-data-neo4j-4neo4j-ogm

Neo4j SDN 4 emulate sequence object(not UUID)


Is it possible in Neo4j or SDN4 to create/emulate something similar to a PostgreSQL sequence database object?

I need this thread safe functionality in order to be able to ask it for next, unique Long value. I'm going to use this value as a surrogate key for my entities.

UPDATED

I don't want to go with UUID because I have to expose these IDs within my web application url parameters and in case of UUID my urls look awful. I want to go with a plain Long values for IDs like StackOverflow does, for example:

stackoverflow.com/questions/42228501/neo4j-sdn-4-emulate-sequence-objectnot-uuid

Solution

  • The most simplest way in Neo4j is to disable ids reuse and use node Graph ID like sequencer.

    https://neo4j.com/docs/operations-manual/current/reference/configuration-settings/

    Table A.83. dbms.ids.reuse.types.override
    
    Description: Specified names of id types (comma separated) that should be reused. Currently only 'node' and 'relationship' types are supported.
    
    Valid values: dbms.ids.reuse.types.override is a list separated by "," where items are one of NODE, RELATIONSHIP
    
    Default value: [RELATIONSHIP, NODE]