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?
As of Neo4j OGM 2.1.0, you can use
@Index
for this. Annotate your field with@Index(unique=true, primary=true)
andsession.save
will use aMERGE
instead ofCREATE
See http://neo4j.com/docs/ogm-manual/current/reference/#reference_programming-model_indexing in the docs