How to reflect “Nested Sets” model in JPA

夙愿已清 提交于 2019-12-08 00:46:38

问题


It is good to use Nested sets for the hierarchical data. But in this design you should calculate always the right and the left nodes if you delete or insert some data. Additionally you don't have any foreignkeys.

How can i reflect this model with JPA?? Is it possible?


回答1:


I think you would still want the PARENT_ID even with the RIGHT and LEFT, otherwise the parent/child queries would be inefficient, or I'm not even sure possible.

The RIGHT and LEFT values you could update in your application/model, or through PrePersist/PreUpdate/PreRemove events.

Another option is to use an exploded table instead. For that you just need to add an allChildren relationship that uses a ManyToMany join table. When you add a child to any node, you just need to add the child to all of its parents.

Yet another option is to just use a hierarchical query in your database, such as a CONNECT BY clause in Oracle.



来源:https://stackoverflow.com/questions/12007148/how-to-reflect-nested-sets-model-in-jpa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!