cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Constraint issue

rcbs0357
Node

Hi - i am a newbie with Neo4J so apologies in advance.

I am developing a java app that sucks model repository knowledge out of a rhapsody model into Neo4J (v3.5.12) for subsequent analysis.
Rhapsody (from a simple single model perspective) guarantees model element uniqueness through an associated GUID.
All nodes have label "Element" but when i am loading the artefacts into Neo4J (via LOAD CSV) i am allocating each node multiple labels based upon where within the Rhapsody type hierarchy the element is situated (so for example a class node may be decorated with labels :Element:ModelUnit:Classifier:Class).
Below is an example of the cypher query i am running using the run method on the session class.

LOAD CSV WITH HEADERS FROM 'file:///C:\\temp\\Class.csv' AS row MERGE (n:Element:ModelUnit:Classifier:Class { ElementGuid: row.ElementGuid}) ON MATCH SET n.OwnerElementMetaClass=row.OwnerElementMetaClass, n.ElementIsReactive=row.ElementIsReactive ON CREATE SET n.ElementGuid=row.ElementGuid, n.OwnerElementMetaClass=row.OwnerElementMetaClass, n.ElementIsReactive=row.ElementIsReactive

My understanding is that using MERGE should take care of both when the node does not already exist and when it does.
Specifically because I am MERGING on label 'Element' (the base type) and discriminating using the unique ElementGuid property then i would have thought that I should end up with each node having a unique elementGuid.

However when i execute
CREATE CONSTRAINT ON (n:Element) ASSERT n.ElementGuid IS UNIQUE
it complains that the constraint cannot be asserted because nodes exist having the same elementGuid property.

I am wondering if it is because in the MERGE I am already allocating multiple labels?

Any thoughts and observations would be most welcome

Rod

3 REPLIES 3

That sounds likely.

MERGE is like a MATCH, and if the match fails, a CREATE. If you may already have the node in your db, but it may not have all the labels, then you should only MERGE on the set of labels that lets you uniquely identify the node (in this case, :Element), and then SET the rest of the labels.

Yes that is my chief suspect at the moment - I'll try it and give some (hopefully +ve) feedback

rcbs0357
Node

Yes that was the problem.