Hibernate 和 GAE 中的树(分层)结构
我想在 Hibernate(以及 GAE)中对分层数据进行建模。
实体结构类似于如下:
class Node<T>
{
Long id;
T nodeValue;
Node<T> parent;
List<Node<T>> children;
}
如果有必要(我认为会有必要),我可以使用 JPA 注释。
应支持以下功能:
添加新根(数据库中可以有多棵树 -。可以不用这个,如果这会导致无法启动设计(通过使用一些“看不见的曾祖父根节点”)parent = null
)- 向任何父节点添加新节点
- 删除节点及其整个子树结构
- 更新节点(例如,更改父/子等)
- 能够在树中自上而下和自下而上移动
- 最重要的是......给定一个
id
,能够获取特定节点然后向上移动(祖先路径)/向下(子路径)
更多信息(更新)
从逻辑上讲,这就是我想要实现的目标:
- 在表中拥有一个简单的类别列表。这些类别彼此没有关系
- 有一个表将为这些类别创建多个“层次结构集”。
为什么我需要它们?
我正在创建一个应用程序,其中可以将文档提交到这些类别。
然而,每个用户对相同类别可能有不同的看法。例如,我可能想创建一个层次结构 Company ->部门->人力资源->世界->亚洲->印度
而其他人可能想看看公司 ->世界->亚洲->印度->部门->人力资源部。
任何对这种结构建模的帮助都会很棒。
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. Can do without this, if this can result in a non-starter to design (by using some "invisible great-grandfather root node")parent = null
)- 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你想要的可能是这样的(来自 Hibernate 的测试套件):
https://github.com/hibernate/hibernate-orm/blob/master/hibernate-core/src/test/java/org/hibernate/ test/annotations/manytoone/Node.java
但如果没有任何具体问题,很难回答......
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...