2

I'm trying to map some JSON objects to java objects and then save these objects to my neo4j db.

I have tried to use simple neo4j-ogm and run: session.save(object), but if some nodes already exist they are duplicated instead of being merged.

If I create a unique constraint on the value, then I get an exception when I try to run: session.save(object) if the nodes already exists.

I would like to know if there is a solution using neo4j-ogm, or i need to add Spring Data Neo4J (SDN) to resolve this problem?

Melebius
  • 6,183
  • 4
  • 39
  • 52
Cezar Sas
  • 306
  • 3
  • 14

1 Answers1

7

As of Neo4j OGM 2.1.0, you can use @Index for this. Annotate your field with @Index(unique=true, primary=true) and session.save will use a MERGE instead of CREATE

See http://neo4j.com/docs/ogm-manual/current/reference/#reference_programming-model_indexing in the docs

Luanne
  • 19,145
  • 1
  • 39
  • 51