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;