-1

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?

digx1
  • 1,100
  • 5
  • 9
Ukis
  • 13
  • 4
  • Welcome to Stack Overflow! Please take the [tour](http://stackoverflow.com/tour), have a look around, and read through the [help center](http://stackoverflow.com/help), in particular [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) and [What topics can I ask about here?](http://stackoverflow.com/help/on-topic). From that second link: "Questions asking for homework help must include a summary of the work you've done so far to solve the problem, and a description of the difficulty you are having solving it." – Timothy Truckle Jan 06 '17 at 23:38
  • Hi, but it's a simple question - I just ask if some of that method exists and, if not, what is the best way to solve this - I don't ask about full solution, just a way to do it and that is not any homework. What have I done already is that I found only solution with db factory, but I trust there is an easier way, like in case of queries or saving. – Ukis Jan 06 '17 at 23:48

1 Answers1

0

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.

digx1
  • 1,100
  • 5
  • 9