-->
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.  [ 4 posts ] 
Author Message
 Post subject: question on lazy loading
PostPosted: Fri May 15, 2009 3:08 am 
Newbie

Joined: Thu May 14, 2009 4:19 am
Posts: 12
There I have Two objects in a one to one relationship.
Class Obj1
{
int Id
string Name
string Obj2Key
}

Class Obj1
{
string Id
string Desc
}


Object1 contains Object2.
I load Object1 and Object2 to is set to lazy using using Obj2Key field. If I access Object1.Object2.Id will that trigger the lazy loading of Object2 - or will it just return the Obj2Key without hitting the database as it already has the value for that field?


Top
 Profile  
 
 Post subject: Re: question on lazy loading
PostPosted: Fri May 15, 2009 3:15 am 
Newbie

Joined: Thu Jan 15, 2009 9:54 am
Posts: 12
Hi Rakesh,
When you load Object 1, object 2 will automatically get loaded, either in the same query or it will use a seperate query.
Lazy loading will not get triggered when u try to access object1.object2.

lazy loading gets triggered only if you have a Collections property in Object 2.

but that too will happen only if your session is not closed.

else you will see an exception.

hope that helps,

Abid


Top
 Profile  
 
 Post subject: Re: question on lazy loading
PostPosted: Sat May 16, 2009 1:47 pm 
Newbie

Joined: Mon May 04, 2009 1:39 pm
Posts: 4
Even in many-to-one relation (by default lazy=true) the lazy loading applies.

The obj2 is not completely loaded along with obj1

When you access obj1.getObj2().getId(), it hits the database and loads the obj2 completely.


Top
 Profile  
 
 Post subject: Re: question on lazy loading
PostPosted: Fri May 22, 2009 9:41 am 
Newbie

Joined: Thu May 14, 2009 4:19 am
Posts: 12
thanks
Rakesh


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