-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hierarchical structure
PostPosted: Fri Oct 08, 2004 5:51 am 
Newbie

Joined: Fri Oct 08, 2004 5:29 am
Posts: 8
Hi there,

I would like to build a hierarchical structure of Items. An item can be a Folder or a Document. Each item except the root folder has exactly one parent folder. All very simple. Now I have two choices:

1) each item has a parent

Code:
public class Item {
  /**
   * @hibernate.many-to-one column="parent_id" class="Folder"
   */
  public Folder getParent() { ... }
}

2) each folder has a set of children

Code:
public class Folder {
  /**
   * @hibernate.set table="folder_children" cascade="all-delete-orphan" lazy="true"
   * @hibernate.collection-key column="item_id"
   * @hibernate.collection-many-to-many column="child_id" class="Item"
   */
  public Set getChildren() { ... }
}

In case one Item.getParent() works out of the box and Folder.getChildren() has to be implemented with a query. In case two the situation is reversed.

So now comes the question: which approach is preferable?

Intuitively I would favour case one but for one problem: When I retrieve a folder that is deep down in the hierarchy Hibernate would have to retrieve all the parents up to the root folder even if I don't need them. If I retrieve all the items in a folder the same would happen for all the items in that folder. Am I right?

Thanks in advance,

Markus


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 3:07 am 
Newbie

Joined: Fri Oct 08, 2004 5:29 am
Posts: 8
Can someone help me on this, please?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 11, 2004 6:08 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
You can map "Folder" as "lazy" to prevent it.


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