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.
source share