-->
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.  [ 7 posts ] 
Author Message
 Post subject: Q: How to Mark collection as loaded (or Tree structure)
PostPosted: Fri Dec 12, 2008 11:17 am 
Newbie

Joined: Fri Jun 08, 2007 4:20 am
Posts: 13
Hello all,

We have a tree structure:

Code:
class Location {
   @OneToMany(cascade = CascadeType.ALL, mappedBy = "parentLocation", fetch = FetchType.LAZY)
   protected SortedSet<Location> childLocations = new TreeSet<Location>();
}


we load all the Locations in one query:
Code:
cache = session.createQuery("from Location");


and then we fill the tree structure like this:
Code:
Location parent;
   for (Location loc : cache) {
      parent = loc.getParentLocation();
      if (parent != null)
         parent.addChildLoc(loc);
   }



Now the question is, how do we mark the 'childLocations' collection as loaded so Hibernate does not try to run a query to load it?

Many thanks


Last edited by montechristos on Mon Mar 30, 2009 8:43 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2008 5:08 am 
Newbie

Joined: Fri Jun 08, 2007 4:20 am
Posts: 13
Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 22, 2008 11:51 am 
Newbie

Joined: Fri Jun 08, 2007 4:20 am
Posts: 13
Bump!

Anyone?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 30, 2009 8:44 am 
Newbie

Joined: Fri Jun 08, 2007 4:20 am
Posts: 13
Bump?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 3:05 am 
Newbie

Joined: Fri Sep 26, 2003 1:50 pm
Posts: 9
Hi,

I haven't seen any sign that you can tell a collection to 'consider' itself initialized.

However, I do wonder whether you aren't better off just managing the collection yourself (i.e. mark it as transient). Since you are loading all nodes and populating the child collections by scanning the loaded nodes, there is not much left that Hibernate does for you (except to generate heaps of unwanted database queries). The only thing that springs to mind is cascading. You would have to persist each tree node explicitly for example.

/Ross.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 8:35 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
if you're loading it manually, why don't you just remove the association in the mapping file.

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 09, 2009 11:10 am 
Newbie

Joined: Fri Jun 08, 2007 4:20 am
Posts: 13
Hi and thanks for the answers.

The idea was not to deal with the collection on our own. Marking it transient or removing the mapping is not exactly what we are trying to do.

The idea was to load the hierarchy, attach the parent to the child in memory, and, for each object, make Hibernate think that it has loaded the particular collection. This way, you would have the benefits of Hibernate dealing with the collection from that moment onwards.

Hibernate uses its own Collection classes to intercept add/remove. Maybe I can cast my Collection to this and try to set its loaded flag...?


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