[英]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.