-->
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: Lazy Loading issue
PostPosted: Fri Oct 27, 2006 9:27 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 2:31 pm
Posts: 25
Location: USA
Hi all,
I have my mapping to load all dependent objects while loading the parent object.
But we may have to load all the top level objects like on findAll method.Only this time we dont want to load all the dependent objects.Is there a way i can load only the top level objects even though mapping it was not set to load lazy ?
Please repond asap.
Thanks,
Vinodh

_________________
I am using a shitty e-mail filtering system that caused a lot of bounces for the admin of this forum. I need to turn on my brain next time and update my e-mail address.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 10:23 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you can always overwrite lazy loading in code. It is more difficult to go the other way.

so declare that relationship to be loaded lazily, and in the code simply make a load method which initializes that collection. This will make the findall only return the top level objects, and the load return the top level objects and its children

_________________
Chris

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


Top
 Profile  
 
 Post subject: Lazy Loading issue
PostPosted: Fri Oct 27, 2006 11:00 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 2:31 pm
Posts: 25
Location: USA
Hi Chris ,
Thanks for your suggestion .Can you please provide a simple code example to overwrite lazy loading in code
Thanks,
Vinodh

_________________
I am using a shitty e-mail filtering system that caused a lot of bounces for the admin of this forum. I need to turn on my brain next time and update my e-mail address.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 11:11 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
Code:
openSession
MyObject object = dao.load(PK);
Hibernate.initialize(object.getChildren());
closeSession


you might have to call object.getChildren().size() inside that initialize method, sometimes it's weird depending on the version of hibernate you're running.

_________________
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: Tue Oct 31, 2006 8:27 pm 
Newbie

Joined: Thu Jun 29, 2006 4:46 pm
Posts: 2
Alternatively, you can use the Criteria Queries which will enable you to selectively override lazy loading at each association level.


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.