How to save a <CustomObject> list as a node property?

I am trying to save a list of class objects, suppose xyz. when I do this in the NodeEntity class:

@Property
List<xyz> listOfConditions

The Node table when loading from the neo4j base using the Neo4jOperations.load (entity) method will return an error: - ERROR maps the GraphModel to a class of type NodeEntity.

Is it possible to save a list of objects in the properties of nodes in Neo4j ?. I am using the neo4j-ogm driver and Spring -data-neo4j.

+4
source share
2 answers

Neo4j does not support saving another object as a nested property. Neo4j-OGM only supports

, String , , , Neo4j node.

, . ,

import org.neo4j.ogm.typeconversion.AttributeConverter

class XYZ{
    XYZ(Integer x, String y) {
        this.x = x
        this.y = y
    }
    Integer x
    String y
}

public class XYZConverter implements AttributeConverter<XYZ, String> {

    @Override
    public String toGraphProperty(XYZ value) {
        return value.x.toString() + "!@#" + value.y
    }

    @Override
    public XYZ toEntityAttribute(String value) {
        String[] split = value.split("!@#")
        return new XYZ(Integer.valueOf(split[0]), split[1])
    }
}

@NodeEntity @Convert,

@NodeEntity
class Node {
    @GraphId
    Long id;

    @Property
    String name

    @Convert(value = XYZConverter.class)
    XYZ xyz
}

, , node XYZ 'hasA'. Neo4j , neo4j

+3

, , node, OGM. - String .

node node .

: http://neo4j.com/docs/ogm-manual/current/

+3

Source: https://habr.com/ru/post/1653639/


All Articles