I am trying to model an object graph of Nodes in a Hierarchy where Nodes have multiple parent Nodes and multiple child Nodes and I need some help! :) Fundamentally, we need to be able to get all of the parents for a given node recursively up the graph very efficiently. For example:
Code:
Given a simple hierarchy 1 --> 2 -->3, the parents for node 3 are 2 and 1.
We need to be able to determine all transitive parents in one sql query.
So far I have been able to create an inverted tree pretty easily. I manually maintained a denormalized version of the parent/child relationships in a separate table. Using the above example, this denormalized table would contain the following rows:
Code:
PARENT_ID, CHILD_ID
2,3
1,3
Using this approach, I can get all of the parents for a given node by joining this table with the Node table. Here are the two questions that I really need some help answering:
1. Can I get Hibernate to maintain this denormalized table automatically with relationships and collection mapping?
2. Is this the best way to model a many-to-many graph when the concerns are good insert performance, excellent select performance (get ALL parents for a given node)?
Thanks!
Lance