Springdata Neo4j primary key -
i new neo4j , sdn . trying create primary key entities using @indexed(unique=true). creates unique nodes replace other properties if used same property value indexed. eg:
class abc{ @indexed(unique=true) long abc_id; string abc_name; } new abc(1,"asd")// creates node id: 1 name : asd new abc(1,"xyz")// replaces asd xyz .
however want throw exception primary key violation/duplicate node.
is there method achieve same?
currently @indexed implementation doesnt throw exception duplicates quoted in jira ticket on spring data neo4j forum : here , in thread
you may create unique nodes running cypher queries (which faster). can use merge create or update nodes.
from documentation
merge either matches existing nodes , binds them, or creates new data , binds that. it’s combination of match , create additionally allows specify happens if data matched or created.
so can below if want update node or create node if pattern doesnt exist.
merge (keanu:person { name:'keanu reeves' }) on create set keanu.created = timestamp() on match set keanu.lastseen = timestamp() return keanu
Comments
Post a Comment