Reputation: 1567
I need to save an Map<Object,List<Object>>
when i populated the containing class the node gets saved but the Map is not.
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
<>
So How can I persist the Map,I am Spring Data Neo4j version 3.3.0.RELEASE
What i want to achieve is to relate the following json to the 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
}
}
}
Upvotes: 3
Views: 1882
Reputation: 1567
as @frant.hartm specified
Other collection types than Set are not supported so far, also currently NO 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.
@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"));
}
Upvotes: 2
Reputation: 15086
This is not supported in 3.x versions:
Other collection types than Set are not supported so far, also currently NO
Map<RelationshipType,Set<NodeBacked>>
.
Upvotes: 1