简体   繁体   中英

Adding non-primitive typed data as property value in nodes and relationships

In neo4j we can add node and relationships with various properties using

node.setProperty("NodePropertyName",NodePropertyValue)
relationship.setProperty("EdgePropertyName",EdgePropertyValue)

Is there any way by which I can use non-primitive datatypes like MAP , Array or user-defined object as NodePropertyValue and EdgePropertyValue ?

Or do i need to give all values in MAP<> individually as separate properties of Node or Relationship ?

I tried using

node.setProperty("USER_PROPERTIES", GraphNode.getNodeproperties());
where,
GraphNode.getNodeproperties() returns MAP<String,Double>

But this is giving me an error:

 java.lang.IllegalArgumentException: Unknown property type on: {Property1=0.0, Property2=0.0, Property3=0.0, Property4=0.0, Property5=0.0, Property6=0.0, Property7=0.0}

Is there any way by which I can use non-primitive datatypes like MAP , Array or user-defined object as NodePropertyValue and EdgePropertyValue ?

Neo4J allows you to store an array of String , or an array of a primitive datatype.

Maps are not supported (yet), but an alternative could be to store the map as a JSON structure (using GSON or Jackson ), or even as an XML structure, using XStream .

You can indeed only store primitive values as properties. If you want to store a collection of values (and if you're using Spring), then DynamicPropertiesContainer might be an option. If you want to store custom objects, you probably want to create some related nodes. Use createRelationshipTo(Node otherNode, RelationshipType type) to accompish this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM