How to reflect "Nested Sets" model in JPA
Asked Answered
F

1

2

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?

Flaming answered 17/8, 2012 at 13:51 Comment(0)
R
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.

Rexanne answered 29/8, 2012 at 12:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.