-->
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: A lazy loaded list
PostPosted: Fri Jan 05, 2007 10:47 am 
Newbie

Joined: Fri Jan 05, 2007 10:37 am
Posts: 2
Hi there. I'm trying to get list of objects by using ISession.CreateQuery() and List<>() - nice, but all related objects are eagerly loaded. When I Load() using a specific ID I get a lazy loaded object - even though this is where I actually want the eagerly loaded data.

I think I've tried all combinations of using lazy=true/false

All hints are welcome - thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 06, 2007 1:39 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I use the original Hibernate in Java, but maybe this is the same. There're two methods to load by id: load() and get(). load() returns a proxy, get() returns null or the object. Maybe you want to call get() instead?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Last edited by batmat on Sun Jan 07, 2007 1:02 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 12:05 pm 
Newbie

Joined: Fri Jan 05, 2007 10:37 am
Posts: 2
Thank you for your input, but I'm afraid it didn't solve my problem. I guess I didn't explain it too well.

For search window purposes, I want to list all objects (filtered by a certain criteria) not including relations to other objects. For this purpose I would expect to use the List<>() method.

When the user selects an object from the search window, I want to load that specific object and (most of) all related objects to that instance. In this case I expect I should use Load/Get.

My problem is that I get the opposite. List gives me all related objects as well, whereas Load/Get gives me the specified object and that's it.

How do I make Hibernate (the problem is properly the same on both platforms) behave as I want?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 07, 2007 1:24 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Which query are you using to retrieve your objects? A criteria query uses the fetch plan defined in the hbm.xml files (i.e. the lazy settings), although a HQL one only retrieves what is asked for.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 14, 2007 9:32 am 
Newbie

Joined: Wed Nov 08, 2006 7:55 am
Posts: 4
First ,You must set your relate object "lazy=tue",so ,The first time Search will only load the object, not load it is relate object,

second, if you want to get the relate object ,you can execute the search
by id again, and use SetFecthMode(FetchMode.eager) to load the relate object,

of cource,you can use NHibernateUtil.Initialize() to load the relate object,too.


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.