Neo4j create node

290 views Asked by At

I'm using repository which extends GraphRepository. It is easy to do some queries or save nodes by derived methods, but is there any simply way to create node? For example, for queries I can use repository.findAll(), to save it is repository.save() but why there is no method like repository.createNode()? If something like that doesn't exist, what is the easiest way to create node?

1

There are 1 answers

0
digx1 On

A node is defined in Spring Data Neo4j (SDN) with the annotation @NodeEntity at the class level on a domain object (POJO). A usual pattern then is for any domain objects that require persistence support you would create a Neo4jRepository or GraphRepository for them. This way when you call repository.save(nodeEntity) you are actually saving the node itself. Having another method like createNode() is therefore redundant.

Remember, save() handles both creation and updating of nodes.