如何使用 Spring Data Neo4j 将 Map (java.util.Map) 对象保留在 NodeEntity 中?

How do I use Spring Data Neo4j to persist a Map (java.util.Map) object inside an NodeEntity?

当我填充包含 class 的节点时,我需要保存一个 Map<Object,List<Object>>,节点已保存,但地图未保存。

这是我为实体使用的代码

    @NodeEntity
    public class UserAlias{
        @GraphId
        private Long id;

        @Fetch
        private Map<IdentityType,List<Permission>> aliases;

        private String name;

    }
......
    userAliasRepo.save(userAlias)

IdentityType 是一个枚举,Permission 是另一个 Class 没有用 @NodeEntity 注释并且 userAliasRepo 扩展 GraphRepository<>

那么我如何持久化地图,我是Spring Data Neo4j 3.3版。0.RELEASE

我想要实现的是将以下 json 与 UserAlias NodeEntity

相关联
{
    "name": "Bond",
    "permissions": {
        "Level5Acess": {
            "READ": false,
            "WRITE": false,
            "CREATE": false,
            "DEL": true
        },
        "Level4Acess": {
            "READ": false,
            "WRITE": false,
            "CREATE": false,
            "DEL": true
        },
        "Level1Acess": {
            "READ": true,
            "WRITE": true,
            "CREATE": true,
            "DEL": true
        },
        "Level0Acess": {
            "READ": true,
            "WRITE": true,
            "CREATE": true,
            "DEL": true
        }
    }
}

3.x 版本不支持:

Other collection types than Set are not supported so far, also currently NO Map<RelationshipType,Set<NodeBacked>>.

http://docs.spring.io/spring-data/data-neo4j/docs/3.4.0.RELEASE/reference/html/#reference_programming_model_relationships_relatedto

如@frant.hartm 指定

Other collection types than Set are not supported so far, also currently NO Map>.

但是可以使用 org.springframework.data.neo4j.fieldaccess.DynamicProperties 代替 Map 然后映射到 node-attributes.The 唯一的权衡是它只支持原始数据类型及其对应的数组。

@NodeEntity
public class Person {
    @GraphId
    private Long graphId;

    private DynamicProperties personalProperties;
    public void setProperty(String key, Object value) {
        personalProperties.setProperty(key, value);
    }

    public Object getProperty(String key) {
        return personalProperties.getProperty(key);
    }
}
@Test
    public void testCreateOutsideTransaction() {
        Person p = new Person("James", 35);
        p.setProperty("s", "String");
        p.setProperty("x", 100);
        p.setProperty("pi", 3.1415);
        persist(p);
        assertEquals(3, IteratorUtil.count(p.getPersonalProperties().getPropertyKeys()));
        assertProperties(nodeFor(p));
        p.setProperty("s", "String two");
        persist(p);
        assertEquals("String two", nodeFor(p).getProperty("personalProperties-s"));
    }

http://forum.spring.io/forum/spring-projects/data/nosql/117145-spring-data-neo4j-how-to-map-java-util-map-string-string-field