-->
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: Initializing collections
PostPosted: Sat Nov 15, 2003 2:04 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 4:19 pm
Posts: 42
Currently, I am retrieving a list of users, then iterating through the list and initializing a collection on each, like so:

Code:
userlist = session.find("from User as user order by username");

...

while(iter.hasNext()){
      User user = (User)iter.next();
      Hibernate.initialize(user.getTeams());
}


This works fine, but each time a collection is initialized, a separate SELECT statement is sent to the DB. Is there a more efficient way to do this, some sort of bulk init, or can I somehow init the collections within my HQL? I don't want to turn off lazy init for this entity, since I only use this collection in one use-case.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 6:53 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You can join to the teams with a fetch will initialise the set in a single query.
Try:

Code:
from User as user left join fetch user.teams order by user.username


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 15, 2003 9:39 pm 
Beginner
Beginner

Joined: Tue Aug 26, 2003 4:19 pm
Posts: 42
That did the trick, thanks very much!


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.