Reputation: 23
I have two entities like Users and Accounts. User node related to Account node with any of the 20 relationships. Please find the sample image design attached
i need to search accounts for corresponding users using any of the 20 relationships. i used the cypher query for retriving user details and the accounts.. Relationship between the two entity will be either any one of the 20 relationships . so i can't annotate the @RelationshipEntity type value. Please find the code for example User.java
public class User
{
private Long id;
String fulltextsearch;
String user_id;
String status;
@Relationship(type = "perm")
List<Acronym> acronym;
.....
...
}
Acronym.java
@JsonIdentityInfo(generator=JSOGGenerator.class)
@RelationshipEntity
public class Acronym {
@GraphId
Long id;
String acronym;
@StartNode
private User user;
@EndNode
private Account account;
....
....
}
Userrepository.java
@RepositoryRestResource(collectionResourceRel = "User", path = "User")
public interface Userrepository extends GraphRepository<User> {
User findByLogin(@Param("login") String login);
@Query("MATCH p=(user:User)-[r*0..1]->(account) WHERE user.login =~('(?i).*'+{Login}+'.*') RETURN p")
Collection<User> findByloginContaining(@Param("login") String login);
}
i tried creating objects for each relationship (ie 20 relationship object.). i'm not sure if that correct way to get the value. Could anyone please help me to know to fetch the relationships against the account? it always retrives as null.
Thanks in advance.
Upvotes: 2
Views: 482
Reputation: 19373
The OGM/SDN 4 does not support unknown relationship types. The type of relationship must be specified on a @RelationshipEntity.
One way of doing this is as you said, create a @RelationshipEntity per type, but this also means that you must specify 20 such relationships in your User class, because the relationship type differs (even though the start/end nodes are the same). This may not be ideal, and difficult to manage.
If your application primarily works with dynamic relationship types, the OGM may not be a good fit.
NOTE: Mapping custom query results to entities is only supported in OGM 2.x / SDN 4.1. You cannot return a path, just the entities that make up the path such as nodes and rels.
Upvotes: 1