简体   繁体   English

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

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

I need to save an Map<Object,List<Object>> when i populated the containing class the node gets saved but the Map is not. 我需要保存Map<Object,List<Object>>当我填充包含的节点时节点被保存但Map不是。

Here is the code I am using for the entity 这是我为实体使用的代码

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

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

        private String name;

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

IdentityType is an Enum and Permission is a another Class not annotated with @NodeEntity and userAliasRepo extends GraphRepository <> IdentityType是Enum, Permission是另一个未使用@NodeEntity注释的类, userAliasRepo扩展了GraphRepository <>

So How can I persist the Map,I am Spring Data Neo4j version 3.3.0.RELEASE 那么我如何坚持Map,我是Spring Data Neo4j版本3.3.0.RELEASE

What i want to achieve is to relate the following json to the UserAlias NodeEntity 我想要实现的是将以下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
        }
    }
}

as @frant.hartm specified 正如@ frant.hartm指定的那样

Other collection types than Set are not supported so far, also currently NO Map>. 到目前为止,还不支持除Set之外的其他集合类型,目前也没有Map>。

But org.springframework.data.neo4j.fieldaccess.DynamicProperties can be used instead of the Map which is then mapped to node-attributes.The only tradeoff is that this only supports primitive dataTypes and their corressponding array. 但是可以使用org.springframework.data.neo4j.fieldaccess.DynamicProperties代替Map,然后映射到node-attributes。唯一的权衡是它只支持原始dataTypes及其corressponding数组。

@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 http://forum.spring.io/forum/spring-projects/data/nosql/117145-spring-data-neo4j-how-to-map-java-util-map-string-string-field

This is not supported in 3.x versions: 3.x版本不支持此功能:

Other collection types than Set are not supported so far, also currently NO Map<RelationshipType,Set<NodeBacked>> . 到目前为止,不支持除Set之外的其他集合类型,目前还没有Map<RelationshipType,Set<NodeBacked>>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用JPA将Map(java.util.Map)对象持久保存在实体中并确保持久性级联? - How do I use JPA to persist a Map (java.util.Map) object inside an entity and ensure the persistence cascades? 如何将对象转发到java.util.Map? - How to upcast an Object to a java.util.Map? java neo4j用cypher创建节点:java.lang.String不能强制转换为java.util.Map - java neo4j creating node with cypher: java.lang.String cannot be cast to java.util.Map 如何回退java.util.Map的版本? - How do I rollback the version of java.util.Map? Spring Data Neo4j在一个NodeEntity中合并不同的类 - Spring Data Neo4j merge different classes in one NodeEntity 如何在Java中将java.util.Map转换为scala.collection.immutable.Map? - How do I convert a java.util.Map to scala.collection.immutable.Map in Java? 为大数据实现java.util.Map - Implementing java.util.Map for big data 如何将json解组到java.util.Map <String, Object> 与MOXy? - How to unmarshal json to java.util.Map<String, Object> with MOXy? Hibernate: How to map java.util.Map with java.util.Set as a value with LocalDate inside? - Hibernate: How to map java.util.Map with java.util.Set as a value with LocalDate inside? 如何在jboss rhpam bpmn的数据对象中为java.util.map添加字段 - How to add fields for java.util.map in data object of jboss rhpam bpmn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM