Romulus
Romulus

Reputation: 1684

Making an Arbitrary Identifier in neo4j

Background

I have a neo4j and spring data framework.

I have a NameType.java which extends my GraphType.java.

My GraphType.java has a Long id and my NameType has a string name

My goal is to eventually make the String name act as a UUID for a all things external (REST etc).

Question

The Long id is automatically made into an @GraphId. I want to make the String name in the NameType into a Arbitrary ID and as such both Unique and Indexed. I am hoping I can just annotate @Id to it as suggested in the docs: https://docs.spring.io/spring-data/neo4j/docs/current/reference/html/#__id_arbitrary_identifier

Am I right? Is this the correct way to go about this?

Upvotes: 2

Views: 104

Answers (1)

František Hartman
František Hartman

Reputation: 15076

You can use @Id for your uuid property, this is replacement for @Index(primary = true, unique = true), it will be used for lookups when calling

  • repository.findOne("uuid")
  • session.load(MyType.class, "uuid")

AutoIndexManager will create correct unique constraint for that.

You still need to have a Long field for the native graph id (either name id or with @GraphId annotation).

Please see the OGM docs for correct version (it seems that SDN docs you link include newer version of ogm docs).

Upvotes: 1

Related Questions