I have a model where User will have a list of Roles and Role has a list of Permissions. However, even when i save all of them at once - with depth -1 I am unable to retrieve the child nodes from the parent nodes. ex: user.getRoles() - 2 [role1,role2] role1.getAssociatedFeature() - 0 But if i get the Role from the DB Ex : findByRoleName('role1') -> [Role: role1,Display Role,associatedFeatures[2]]
User.java
@NodeEntity
public class User {
@GraphId Long id;
private String name;
private String loginUserName;
@Relationship(type="ROLE")
private Set<Role> associatedRoles = new HashSet<Role>();
} Role.java
@NodeEntity
public class Role {
@GraphId Long id;
private String roleName;
private String displayRoleName;
@Relationship(type="ACCESS_TO")
private Set<Feature> associatedFeatures = new HashSet<Feature>();
}
Feature.java
@NodeEntity
public class Feature {
@GraphId Long id;
private String featureName;
@Relationship(type="HAS_PERMISSION")
private Set<Permission> permissions = new HashSet<Permission>();
}
@NodeEntity
public @Data class Permission {
@GraphId
Long id;
String permission;
}
I am using Spring data jpa to use the CRUD operations: <>Repository.java - This will bydefault implement save,update,delete,find
@RepositoryRestResource()
public interface RoleRepository extends GraphRepository<Role>{...}
ServiceImpl.java
@Override
public User create(User u) {
return userRepo.save(u,-1);
}
In my Junit- I am creating a new User entity, and populating the data all the way to permission. But when i fetch the user -> i only get the roles but not the features, permission along the chain.
In the neo4j DB browser, I see that all the nodes are created with appropriate dependency. Any pointers on how to save and traverse through the graph?