Tree (hierarchical) structure in sleep mode and GAE

I want to model hierarchical data in Hibernate (as well as in GAE).

The structure of the entity is similar to the structure:

class Node<T> { Long id; T nodeValue; Node<T> parent; List<Node<T>> children; } 

I am fine using JPA annotations if necessary (which I think will be).

The following features should be supported:

  • Adding a new root (there may be several trees in the database - parent = null ) . You can do without this if it can lead to creation without a starter (using some "invisible root of great-grandfather node")
  • Adding a new node to any parent
  • Removing node and entire tree structure
  • Updating a node (say changing a parent / children, etc.)
  • Ability to move from top to bottom as well as from bottom to top in a tree
  • And most importantly ... Given the id , the ability to get a specific node, and then move up (ancestor path) / down (child path)

Additional information (updates)

This is what I logically want to achieve:

  • You have a flat list of categories in the table. These categories are not related to each other.
  • You have a table that will create several β€œsets of hierarchies" for these categories.

Why do I need them?

I am creating an application in which documents can be submitted in these categories.

However, each user may have a different viewpoint for the same categories. For example, I can create a hierarchy Company -> Departments -> HR -> World -> Asia -> India , while someone else might want to see Company -> World -> Asia -> India -> Departments -> HR .

Any help in modeling this structure would be great.

+4
source share
1 answer

What you want is probably something like this (from the Hibernate test suite):

https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/test/annotations/manytoone/Node.java

But without any specific question, it’s hard to answer ...

-1
source

Source: https://habr.com/ru/post/1337115/


All Articles