-->
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.  [ 6 posts ] 
Author Message
 Post subject: Implementing a tree structure for domain objects
PostPosted: Mon Jan 15, 2007 10:17 am 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
Greetings.

I am working on creating a tree structure to hold my domain objects.
The tree should hold an infinite level and amount of nodes, and each node hold one object (but the same object can be held by multiple nodes). These objects are typically Users, user groups, articles, folders, comments et.c.

To illustrate:
Code:
|-Object A
|
|-Object B
| |
|  - Object A
| |
|  - Object D
|    |
|     - Object C
|-Object C



I have followed a tutorial I found at http://www.thogau.net/tutorials/tree/, and so far so good. In this example each node merely contains a string, and I want to hold an object. So i believe I have to go with one of the three approaches to inheritance mentioned in chapter 3.6 in "Hibernate In Action": Table per concrete class, table per class hierarchy or table per subclass. Of wich the "Table per class hierarchy" seems most appealing to me at first sight.

Am I correct in my reasoning for the use of inheritance and is the "Table per class hierarchy" a suitable method in this scenario? Also, is the approach to a tree structure outlined in the tutorial a sensible way?

Regards,
daijavad


Top
 Profile  
 
 Post subject: Partial solution, similar problem
PostPosted: Wed Feb 07, 2007 2:21 am 
Newbie

Joined: Wed Feb 07, 2007 1:22 am
Posts: 2
Location: Vancouver, WA
Post retracted

_________________
Snake, we need more wine!


Last edited by bklough on Sat Feb 24, 2007 12:07 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 7:30 am 
Newbie

Joined: Fri Jan 19, 2007 1:41 pm
Posts: 8
What do your hibernate mappings look like? You should have a one-to-many in your relationships somewhere. If you want the relationship bi-directional you also need a many-to-one and an inverse flag set to true on the one end. Do you have all that stuff set up right? Without it Hibernate won't know how to form queries to return your graph.

I have a parent child hierarchy returning data accurately which is 6 levels deep. I'm just tackling lazy loading.

Don't suppose you know how to switch on Hibernate debug logging?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 12, 2007 7:48 am 
Newbie

Joined: Mon Jan 15, 2007 9:51 am
Posts: 17
bklough, thanks for the link and your input!

@simonjpalmer:
My initial question is more related to what is considered best practice/most efficient when implementing a tree structure that can hold objects of (very) different classes (so some level of inheritance is probably required). What strategy for inheritance have you used in your implementation?

Creating a structure that just holds strings or one kind of object is rather trivial according to the link I mentioned in my first post...


Top
 Profile  
 
 Post subject: Not worth the effort
PostPosted: Sat Feb 24, 2007 12:04 am 
Newbie

Joined: Wed Feb 07, 2007 1:22 am
Posts: 2
Location: Vancouver, WA
Despite the claims and attraction of supposed ORM with Hibernate, don't use Hibernate for OO hierarchies -- it's not worth the effort. Treat the db as a big bucket, use simple, minimal hbm.xml maps to get data into some semblance of an object (dao), then use that brain-dead dao to populate a real object and do what you have to do. This is one of those areas where Hibernate looks like a Ferrari, but drives like a Model T milk truck.

sql2java would probably give you what you need from the gitgo, minus the huge maintenance cost for all the .xml and tag stuffage and diagnosing the performance hit of a gazillion queries it does under the covers.

Just my two cents. Good luck and cheers.

_________________
Snake, we need more wine!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Feb 25, 2007 3:24 am 
Newbie

Joined: Wed Nov 30, 2005 4:13 pm
Posts: 12
Table per class hierarchy is the best choose for this case. You should have one node class for each object type the node holds. This way is easy to point on held object with many-to-one relation. Very important is how many objects your tree will contain. If your tree will be not too large then method shown in this tutorial http://www.thogau.net/tutorials/tree/ doesn't hit performance much. But if not you should implement selecting tree in more sofisticated maner - but this depends on your tree structure. Is it one big tree wheter it is forest with many separate trees? Will you have to fetch some subtree with its nodes?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.