0

I have created a neo4j model with text file of cypher statements. Now i'd like to create an application that uses this database, and I'll be using SDN4. In my @NodeEntity class, I will need to have the GraphID of type Longdeclared. But this ID gets generated by SDN4, and my database doesn't have those IDs. Is there a way to have those created via Cypher so I can simply have my Java objects mapped correctly to the pre-existing nodes and relationships in the database?

Luanne
  • 19,145
  • 1
  • 39
  • 51
aaaaarrrgghhh
  • 397
  • 5
  • 16

1 Answers1

1

The @GraphId field is always the internal node or relationship ID assigned by Neo4j and cannot be set to custom values. You're probably looking to assign your own ID value as a property of the node. This can be done by adding your own id field-

@GraphId Long graphId; //required, this is the internal node/rel ID that must never be assigned by your code
Long id; //your own primary key

Now, when your database contains nodes with a property id assigned by the statement in your Cypher script, loading the entities via SDN will populate these id fields in your domain object.

If you do not have your own primary keys but want an ID anyway, you can use a UUID plugin that will automatically assign UUID's to nodes when they're created via any means (SDN/Neo4j browser/API's etc.).

Luanne
  • 19,145
  • 1
  • 39
  • 51
  • just to clarify, the `graphID` mentioned above is populated by SDN or neo4j? When I'm creating the node from Cypher, it gets an ID. Will this ID get mapped to the `graphID` automatically? In that case i don't need an additional UUID field - i just want my objects mapped correctly to preexisting nodes! I was under the impression that the GraphID has to be generated by SDN... – aaaaarrrgghhh Jun 15 '16 at 08:44
  • The graphId is generated by Neo4j. When you create a node via Cypher, Neo4j assigns this ID. When you load the node via SDN, then that ID is mapped to the graphId for you – Luanne Jun 15 '16 at 08:53