Neo4j does not support storing another object as a nested property. Neo4j-OGM only supports
any primitive, boxed primitive or String or arrays thereof,
essentially anything that naturally fits into a Neo4j node property.
If you want to work around that, you may need to create a custom type convertor. For example,
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])
}
}
You can then annotate the @NodeEntity with a @Convert like this
@NodeEntity
class Node {
@GraphId
Long id;
@Property
String name
@Convert(value = XYZConverter.class)
XYZ xyz
}
On the flip side, its not a good practice to do this, since ideally you should link Node and XYZ with a 'hasA' relationship. Neo4j has been designed to optimally handle such kind of relationships, so it would be best to play with to strengths of neo4j