-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: [Newbie] Slightly unorthodox tree structure
PostPosted: Mon Mar 28, 2011 11:32 pm 
Newbie

Joined: Fri May 21, 2010 8:53 pm
Posts: 8
All -

Thanks in advance for any help. Here goes:

I have a bunch of objects that I want to organize in tree structures, but the same node can be present multiple times in a single tree, and the same node can be present in multiple trees. That is, the nodes in the trees are really types of objects; I don't really want to treat the same type of node as two disparate objects if it is present in two trees, for example. The trees would thus look something like the following:

Code:
     V          S     A     B     D     E     V
    / \        / \                           /|\
   A   B      C   V                         A B C
                 /|\
                A B D


So, in the above example diagram:
  • Tree 1 has V as a parent to nodes A and B.
  • Tree 2 has S as a parent to nodes C and V; V, in turn, is a parent to nodes A, B, and D.
  • Tree 3 consists of a single node, A.
  • Tree 4 consists of a single node, B.
  • Tree 5 consists of a single node, D.
  • Tree 6 consists of a single node, E.
  • Tree 7 has V as a parent to nodes A, B, and C.

To store the above data, in order to avoid storing multiple rows for each type of node (for example, node A is in three trees, but I wouldn't want to store three rows) what I thought I would do is something like this:

Code:
                                              Table NODES
                                              id          node type
                                              ----------- ------------
                                              1           A
                                              2           B
                                              3           C
                                              4           D
                                              5           E
                                              6           S
                                              7           V

                                              Table NODE_LINKS
                                              id             node_id            parent_id   tree_id
                                              -----------    -----------------  ----------- ----------
                                              1              7                  NULL        1
                                              2              1                  7           1
                                              3              2                  7           1
                                              4              6                  NULL        2
                                              5              3                  6           2
                                              6              7                  6           2
                                              7              1                  7           2
                                              8              2                  7           2
                                              9              4                  7           2
                                              10             4                  NULL        3
                                              11             4                  NULL        4
                                              12             4                  NULL        5
                                              13             4                  NULL        6
                                              14             7                  NULL        7
                                              15             1                  7           7
                                              16             2                  7           7
                                              17             3                  7           7



Table TREES
(consists of an id field; maybe some non-key fields, but I don't think they are germane to the example)



Any tips on how I should tackle this? Is there anything in a Hibernate mapping that I can take advantage of, or do I have to completely roll my own for everything (meaning, do I have to manually put together the NODE_LINKS table objects and save them, or there, by some chance, some sort of collection mapping I can use that will handle that for me)?

Thanks very much!


Top
 Profile  
 
 Post subject: Re: [Newbie] Slightly unorthodox tree structure
PostPosted: Wed Mar 30, 2011 9:09 am 
Newbie

Joined: Fri May 21, 2010 8:53 pm
Posts: 8
Bump.

What is with this community? It doesn't seem very active.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.