cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Spring Boot Neo4jRepository find methods

apilipchyk
Node

Hi)
When I try to use findAll or findById repository methods I haven't get result (I have get java heap space error)

Spring Boot version 2.4.1
I use spring-boot-starter-data-neo4j

My entities:

@Data
@Node("Template")
public class TemplateEntity {

    @Id
    @GeneratedValue
    private Long id;
    private String name;
    @CreatedDate
    private LocalDate dateCreated;

    @Relationship(type = "HAS_AUTHOR")
    private UserEntity author;

    @Relationship(type = "IN_TEMPLATE_FOLDER")
    private TemplateFolderEntity folder;

    @Relationship(type = "HAS_QUESTION")
    private Set<TemplateQuestionRelationship> questions = new HashSet<>();
}

@Data
@Node("TemplateFolder")
@EqualsAndHashCode(of = {"name"})
public class TemplateFolderEntity {

    @Id
    @GeneratedValue
    private Long id;

    private String name;

    @CreatedDate
    private LocalDate dateCreated;
    @LastModifiedDate
    private LocalDate dateModified;

    private boolean root = false;

    @Relationship(type = "HAS_CHILD_FOLDER")
    private Set<TemplateFolderEntity> children = new HashSet<>();
}

Nodes example:
3X_c_8_c80f860603d77637a4e379ae6a8522735dc410fd.png

I have relationship only between Template and TemplateFolder (for test)

When I try to select template by id I expect that db find my template and will go to all nodes that my template has with OUTGOING relationship. But seems db processing all relationship nodes (with relationship incoming/outgoing) and my query never ends.
When I testing logic with one template node in db I have get result.

Somebody can help me, what I did not correctly? Thanks)

4 REPLIES 4

gerrit_meier
Neo4j
Neo4j

Could you please add the other entity classes like UserEntity and TemplateQuestionRelationship here? Or at least tell me if the UserEntity has additional relationships and what the target node of the TemplateQuestionRelationshipis and if this also has additional relationships defined?
I assume that the heap space error comes from the database, right?
There might be a more complicated schema cycle that the database cannot easily resolve. But to look into this I really need the whole domain model you are defining.

Hi, Gerrit. Thank you for your fast reply.

@Data
@Node("User")
@NoArgsConstructor
@AllArgsConstructor
public class UserEntity {

    @Id
    @GeneratedValue
    private Long id;
    private String firstName;
    private String lastName;
    private String email;
    private String password;
    private boolean disable;
    private boolean locked;
    private boolean removed;
    @CreatedDate
    private LocalDate registeredDate;

    @Relationship(type = "HAS_PERMISSION", direction = Relationship.Direction.OUTGOING)
    private PermissionEntity permission;

    @Relationship(type = "HAS_EMPLOYMENT_PERIOD", direction = Relationship.Direction.OUTGOING)
    private List<EmploymentEntity> employments = new ArrayList<>();
}

@Data
@Node("Permission")
@NoArgsConstructor
@AllArgsConstructor
public class PermissionEntity {

    @Id
    private Integer permissionId;
    private String role;
    private String value;
    @Version
    private Long version;
}

@Data
@Node("Employment")
@AllArgsConstructor
@NoArgsConstructor
public class EmploymentEntity {

    @Id
    @GeneratedValue
    private Long id;
    private LocalDate start;
    private LocalDate end;

    @Relationship(type = "EMPLOYMENT_BY", direction = Relationship.Direction.OUTGOING)
    private DepartmentEntity department;

    public EmploymentEntity(LocalDate start, LocalDate end, DepartmentEntity department) {
        this.start = start;
        this.end = end;
        this.department = department;
    }
}

@Data
@Node("Department")
@NoArgsConstructor
@AllArgsConstructor
public class DepartmentEntity {

    @Id
    @GeneratedValue
    private Long id;
    private String region;
}
@Data
@RelationshipProperties
public class TemplateQuestionRelationship {

    @Id
    @GeneratedValue
    private Long id;
    private String groupName;
    private Long parentQuestionId;
    private Integer answerId;

    @TargetNode
    private QuestionEntity question;
}

@Data
@Node("Question")
public class QuestionEntity {

    @Id
    @GeneratedValue
    private Long id;
    private String name;
    @CreatedDate
    private LocalDate dateCreated;
    @LastModifiedDate
    private LocalDate dateModified;

    @Relationship(type = "FROM_QUESTION_SOURCE")
    private QuestionSourceRelationship source;
}

@Data
@RelationshipProperties
public class QuestionSourceRelationship {

    @Id
    @GeneratedValue
    private Long id;
    private String documentParagraph;

    @TargetNode
    private QuestionSourceEntity source;
}

@Data
@Node("QuestionSource")
public class QuestionSourceEntity {

    @Id
    private String id;
    private String name;
    private String link;
}

Yes, heap space error comes from the database, I'm shure about that. I have make debug and test many time and have got good result only in case when TemplateFolder didn'd had any other relatoinships.
if I did mistakes in message, sorry for my English)

@gerrit.meier it seems the problem is with SDN 6 where the self reference nodes in the model generate a query that eats up the entire heap and eventually fails.

SDN 6 removed @Depth annotation and now tries to retrieve entire reachable graph in findBy* methods. See: SDN6.0.3 findBy* methods slowing down heavily for a small number of nodes. · Issue #2131 · spring-pr...

I'm trying to downgrade to 5.3.6 since this issue is a showstopper for me.

apilipchyk
Node

Hi. Reason of problem is relationship HAS_CHILD_FOLDER. I don't know why this happen but if your node have relationship with other node with same type you sometime can get error with nodes processing. I updated my db structure and removed relationship and now everything work correctly.