-->
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: force loading of nested lazy collections
PostPosted: Fri Jul 17, 2009 6:02 am 
Newbie

Joined: Fri Jul 03, 2009 1:32 am
Posts: 7
Hi,
The scenario is as follows
Company object which contains a List of Employees, and each Employee object has List of Address objects.

I have lazy loading enabled for all the collections since I dont want to load the entire object tree to be loaded all the time.

Now my concern is, when I need the collections including the nested one (i.e list of Address for each Employee) , how can I force this
I have used Hibernate.initialize(company.getEmployee()) to load the list of employee.But how can I apply this to the inner collection of Address , for each employee
what I have done is below
Code:
Hibernate.initialize(company.getEmployee())
Itarator<Employ> empItr=company.getEmployee();
Employ emp=null;
while(empItr.hasNext()){
  Hibernate.initialize(emp.getAdresses());

}

But I dont tink this is the best way to do this.Can anybody suggest a better solution?

Shaiju
Scientia


Top
 Profile  
 
 Post subject: Re: force loading of nested lazy collections
PostPosted: Fri Jul 17, 2009 7:37 am 
Beginner
Beginner

Joined: Wed Jun 17, 2009 9:03 pm
Posts: 31
Location: mumbai
Need to select fetch strategy as join or may be select. Something like this

Code:
<class name="Company" table="Company">
...
<set name="bids" inverse="true" fetch="join">
   <key column="companyId"/>
   <one-to-many class="Employee"/>
</set>
</class>


will result in this query at loading company and employee in same query.Although need to check for nested collection.

Code:
select c.*, e.*
from company c
left outer join Employee e on c.companyId = e.companyId


Top
 Profile  
 
 Post subject: Re: force loading of nested lazy collections
PostPosted: Fri Jul 17, 2009 7:43 am 
Newbie

Joined: Fri Jul 03, 2009 1:32 am
Posts: 7
Thanks for the response.
But this is not what I wanted.I dont want to load the employee list all the time.I wanted to load this only in specific case.So I can not give the mapping in the mapping file.
Also the issue is with the inner collection ,say employ.addresses.Not with the employee collection.


Shaiju


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.