-->
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: How to retrieve a nested tree structure of unknown depth
PostPosted: Tue Jun 13, 2006 7:16 am 
Newbie

Joined: Tue Jun 13, 2006 7:05 am
Posts: 1
Hi,

I'm using hibernate 3 and I have a table which contains nodes of a tree I want to display on the screen. I need to pass the tree data to my app as an XML document.

My hibernate mapping file for this table is shown at the end of the email.

I can get the hibernate code working fine to save and retrieve nodes and even access their children. My question is this - If I want to pull back a complete set of rows (maybe filtered and sorted by name) and build the xml to represent the tree, what is the most efficient strategy for this. I have read Hibernate in Action and seen some strategies regarding lazy loading and fetch depth but presumably at some point I may go beyond this depth and end up pulling back proxies.

Can anyone point me at a good article on saving and retrieving tree structures (it doesn't necessarily need to involve hibernate I guess). I've looked around but can't seem to find anything relevant.

Many thanks,
David

?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.accipia.centerview.model">
<class name="Objective" table="objectives">
<id name="id" type="long">
<column name="id" />
<generator class="native" />
</id>
<property name="shortName" type="string">
<column name="short_name" length="50" />
</property>
<property name="longName" type="string">
<column name="long_name" />
</property>
<property name="version" type="long">
<column name="version" />
</property>
<property name="description" type="string">
<column name="description" length="65535" />
</property>

<many-to-one
name="parent"
class="Objective"
column="parent_id"
cascade="none"/>

<set
name="children"
table="objectives"
cascade="save-update"
inverse="true">
<key column="parent_id"/>
<one-to-many class="Objective" />
</set>
</class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 13, 2006 10:16 am 
Newbie

Joined: Thu Jun 01, 2006 5:43 am
Posts: 3
Hi,

for saving, I am using a simple Pojo:
Code:
@Entity
public class MyClass  implements Serializable {

   private static final long serialVersionUID = -1662397053835259063L;

   @Id
   Long id;

   @ManyToOne
   @JoinColumn(name="PARENT_ID",unique=true)
   private MyClass parent;


For retrieving the data I'm mostly writing a selectable recursive stored procedure which reads the values from the tree and sorts them in a more "displayable" kind with a level and a position field. With XML I would display them with the tag names in the first field and the value of the field in the second etc. fields.

Chris


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.