-->
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: Accessing objects tree structer
PostPosted: Wed Aug 05, 2009 2:40 pm 
Newbie

Joined: Sun Jun 17, 2007 4:01 pm
Posts: 5
Hi,
i have a Class Category which has subcategories collection of type Category. Each Category object has also a superCategory reference to it's parent Category object, so it's typical tree structer with many roots possible. All i need to do is to retreive all my Category objects from database as tree structer, not as a list of all Category objects but as a list of root level Category objects and eagerly retreived subcategories, and subcategories of subcategories and so on.

I tried this
Code:
session.createCriteria(Category.class).add(Expression.isNull("superCategory")).setFetchMode("subcategories",FetchMode.EAGER).list();


but is retreives just a plain list of all Category objects, not a tree structer.

Example of my tree structure could be as below:

Category
-Category
--Category
--Category
---Category
---Category
--Category
---Category
Category
-Category
--Category
---Category

The question is: how to retreive all Category objects as a tree structer?

Thanks for any helpful answers


Top
 Profile  
 
 Post subject: Re: Accessing objects tree structer
PostPosted: Mon Aug 10, 2009 7:16 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Do you have a recursive mapping in your hibernate configuration file for this class? Does the actual mapping reflect this recursive structure?

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject: Re: Accessing objects tree structer
PostPosted: Wed Aug 12, 2009 2:06 am 
Beginner
Beginner

Joined: Wed Dec 10, 2008 5:59 am
Posts: 47
I worked on something quite similar i little while ago, and i write things down just to remember it. Have a look and see if it can help you a little on your way.

http://blog.brattland.no/?q=node/3

Returning only the root category objects should be as simple as iterating over the results and returning only those objects that do not have a parent.


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.