问题
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