开发者

Tree (Hierarchical) Structure in Hibernate and GAE

I want to model a hierarchical data in Hibernate (and also in GAE).

The entity structure is similar to as below:

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

I am fine with using JPA annotations, if that's necessary (which I think will be).

The following features should be supportable:

  • Adding a new root (there can be multiple trees in the database - with parent = null). Can do without this, if this can result in a non-starter to design (by using some "invisible great-grandfather root node")
  • Adding a new node to any parent
  • Deleting a node and it's entire sub-tree structure
  • Updating a node (say, changing parent/children etc)
  • Ability to travel top-down as well as bottom-up within a tree
  • And most importantly... Given an id, ability to fetch the specific node and then travel upwards (ancestor-path) / downwards (children-path)

More Info (Updates)

Here's what I logically want to achieve:

  • Have a flat list of categories in a table. These categories have no relation with each other
  • Have a table that will create multiple "set of hierarchies" for these categories.

Why do I need them?

I am creating an application wherein documents can开发者_如何转开发 be submitted to these categories.

However, each user may have a different view point to the same categories. For example, I may want to create a hierachy Company -> Departments -> HR -> World -> Asia -> India whereas somebody else may want to see Company -> World -> Asia -> India -> Departments -> HR.

Any help to model this structure will be great.


What you want is probably something like this (from Hibernate's 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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜