Hi, I can't seem to remove a an entry from a map property of a node. For instance if the node Test
with id "testId" has a map with the mapping "1" to "2" the code below will not remove that entry.
class Test {
@Id String id;
@Properties
Map<String, String> map;
}
// This code will not remove the "1" to "2" mapping from the database.
public static void main(String[] args) {
Test test = session.load(Test.class, "testId");
test.map.remove("1");
session.save(test);
}
}
Edit:
Found a way to circumvent this by using an AttributeConverter instead of the @Properties notation. Since removing and adding things from lists seem to be easier with the OGM framework this code worked:
public class MyMapConverter implements AttributeConverter<Map<Integer,Integer>, List<Long>> {
@Override
public List<Long> toGraphProperty(Map<Integer, Integer> map) {
if (map == null) {
return null;
}
List<Long> list = new ArrayList<>();
map.forEach((key, value) -> {
list.add((((long) key) << 32 ) | value);
}
);
return list;
}
@Override
public Map<Integer,Integer> toEntityAttribute(List<Long> list) {
Map<Integer,Integer> map = new HashMap<>();
list.forEach(entry -> map.put((int) (entry >> 32), (int) (long) entry));
return map;
}
}