Hi everyone,
I'm new to neo4j, I have one question hoping someone more experienced could help.
So I need to model one to many relationship within User type, the use case is that a user can be lead to another user, so on my UserEntity I want to have "lead" attribute which will be lead of user if he has it, and also "mentees" attribute which will be list of users which that user leads if he leads some.
Here below you can see how I modelled my UserEntity
@Node("User")
public class UserEntity {
@Id
private String userName;
@Property("password")
private String password;
@Relationship(type = "IS_LEAD_BY", direction = Relationship.Direction.OUTGOING)
private UserEntity lead;
@Relationship(type = "IS_LEAD_BY", direction = Relationship.Direction.INCOMING)
private Set<UserEntity> mentees;
And down below you can see the response I get when fetching user:
{
"userName": "user1",
"password": "pass1",
"lead": {
"userName": "user2",
"password": "pass2",
"lead": null,
"mentees": [
{
"userName": "user1",
"password": "pass1",
"lead": {
"userName": "user2",
"password": "pass2",
"lead": null,
"mentees": [
{
"userName": "user1",
"password": "pass1",
"lead": {
"userName": "user2",
"password": "pass2",
"lead": null,
"mentees": [...
Basically the problem is in response I get endless loop, because user 1 has lead user2, which then again has user1 as mentee and it goes on like this.. Is it somehow possible to limit depth for the attribute or something like that? Is there a better way to model entity?
Hope someone answers my question, looking forward to it.
Have a great day