0
votes

I would like to model hierarchical entities that have ancestors and descendents (tree-like relationships). In more detail my entities (nodes) have one parent and an arbitrary number of children of the same class. Is the following code valid and sound or is there a better way to implement this? Does the fetch annotation mean that the children Set will be filled automatically depending on how many nodes have as a parent this.ProductClass?

@NodeEntity
public class ProductClass {

@GraphId
private Long id;
@Indexed
private String name;
private String leveltype;
private String description;

@Fetch 
@RelatedTo(type = "PARENT", direction = Direction.INCOMING)
Set<ProductClass> children;

@RelatedTo(type = "PARENT", direction = Direction.OUTGOING)
ProductClass parent;
1

1 Answers

1
votes

Is the following code valid and sound or is there a better way to implement this?

The code looks good for what you have described. The best way to validate is to unit test.

Does the fetch annotation mean that the children Set will be filled automatically depending on how many nodes have as a parent this.ProductClass?

That is correct. If this ProductClass has 100 children then all the hundred will be fetched. This means that you incur a performance hit.