-->
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: Level fetching on same table.
PostPosted: Wed Nov 30, 2005 3:46 pm 
Newbie

Joined: Mon Nov 28, 2005 11:15 am
Posts: 13
Hibernate version:3.0
Name and version of the database you are using:MySQL

Hi All,

I am playing with the Category example from Hibernate in Action where a Category has sub categories etc.

Could someone suggest a way to detect the level (depth) of a Category in the tree?

For example CategoryA has Category B has Category C, I would like to be able to execute a method in the category object as category.getLevel() to return the level of the category.

I could compute the same with an algorithm but do not want to fetch the children or parents if I can avoid it.

Thanks in advance


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 30, 2005 4:01 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This would need a recursive algorithm or the storage of explicit level information for each node. You might want to check out the latest CaveatEmptor and the nested set stuff in there. With nested set information (search Google if you don't know what this is) you can calculate the depth of nodes with a subtree query.


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.