Question

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?

Était-ce utile?

La solution

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top