Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-04-2019 06:22 AM
Consider the following classes:
@NodeEntity
class MyClass {
@Id @GeneratedValue
Long iid;
List<Attribute> attributes;
}
class Attribute {
String name;
String value;
}
In order to be able to store "attributes" in the node corresponding to the MyClass object without a need to store each attribute as a distinct node, I want to convert them to multiple attributes when saving to neo4j, something like this:
@NodeEntity
class MyClass {
@Id @GeneratedValue
Long iid;
String attribute_name1; // (which stores value1)
String attribute_name2; // (which stores value2)
String attribute_name3; // (which stores value3)
}
However, it seems that @Convert is only able to convert an attribute to a single attribute with the same name not several attributes with different names. I would be happy to be able to do something like this:
@NodeEntity
class MyClass {
@Id @GeneratedValue
Long iid;
@MultipleConvert(MyConverter.class)
List<Attribute> attributes;
}
class MyConverter<T> implements IMultipleConvert<T>{
@Override
public List<Pair<String, String>> toGraphProperty(List<T> list) {
...
return convertedList; // This returns, e.g., [{name1, value1}, {name2, value2}] which will be stored as attributes "attribute_name1", ... in the graph node.
}
@Override
public List<T> toGraphProperty(List<Pair<String, String>> list) {
...
return convertedList;
}
}
Is it possible in Neo4j OGM? If not, is there any plan to add it?
Is it possible that the graph properties have different types (e.g., one is a number, another is a string)?
Solved! Go to Solution.
08-04-2019 09:41 PM
CompositeAttributeConverter seems to be the solution to my problem. It supports properties having different types.
08-04-2019 04:03 PM
Seems like a good case for using lists, which are supported in OGM and Neo4j.
Also note that graph properties do have different types (the current documentation can be misleading).
08-04-2019 09:41 PM
CompositeAttributeConverter seems to be the solution to my problem. It supports properties having different types.
All the sessions of the conference are now available online