-->
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.  [ 5 posts ] 
Author Message
 Post subject: how to use lazy collections when not using openSessionInView
PostPosted: Fri Nov 21, 2003 11:44 am 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
anyone have ideas on what a good way to tell my service layer what data to initialize from objects it returns?

im not using the open-session-in-view pattern here.

for example my UserService.getUser(Long id)

say User has a Roles List, (list of Role objects) how should I tell my UserService.getUser() method what collections to load?

I dont want to have methods like getUserWithRoles()

another issue is like what if a Role object has a lazy Groups collection, how could I load all the Groups in the Roles? do I really need to iterate thru roles and use Hibernate.initialize on role.getGroups?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 2:06 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
is there a way to load several collections at once in one query?

like in my previous example:

User.getRoles(): list of Role objects
Role.getGroups(): list of Group objects

can i load that in one hql query?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 6:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
No, its not currently possible to load multiple collections at once. It is, however, possible to load tuples of the associated objects in a single select.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 7:23 pm 
Regular
Regular

Joined: Tue Aug 26, 2003 6:59 pm
Posts: 89
Location: Somewhere in the Ghetto
gavin could you provide an example how I would get data using a tuples?

currently the best i've done in getting multiple collections initialized is:

User user = (User) baseService.load(User.class, 1, new String[]{"getRoles","getGallerys","getImages"});


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 21, 2003 8:26 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Code:
result = session.find("select user, role, gallery from User user join user.role role join user.gallery gallery where user.id= ?, ...)


returns a list of Object[3]

_________________
Emmanuel


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