-->
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.  [ 7 posts ] 
Author Message
 Post subject: Loading objects with Uninitialized Collections through Query
PostPosted: Mon Dec 15, 2003 5:19 am 
Newbie

Joined: Sun Nov 30, 2003 4:46 am
Posts: 17
My problem is that if a Parent class contains a collection of Child classes
and they are to be lazily loaded.
How can I load a Parent object, through a Query, with its collection uninitialized?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 8:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
can't really understand your pb
Code:
from MyObject
will load myObjects wo initializing their lazy collections

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:05 am 
Newbie

Joined: Sun Nov 30, 2003 4:46 am
Posts: 17
To be more specific,

When I load my Parent object using session.load() the object is loaded but its collection of Child objects are not initialized since they are to be lazily loaded later.
I want to achieve this same kind of loading by using a hibernate query
The problem that Im facing is that when I try to load Parent using a query
supposing session.iterate("from Parent"), its collection also gets initialized which I dont want it to be. I want the collection to be lazily loaded that is when I access them.
Im confused as to which hibernate api's method to use to achieve my requirement.

Thanx in advance for any suggestions and tips


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:09 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Session.iterate("from Parent") should definately not initialize lazy collections. You are surely refering to your collection somewhere in your code causing it to be initialized. Please show us your code if you don't find this yourself.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:11 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Not loading collections is the default behavior, what is the query that fetch your collections despite the lazy loading ?
You don't use the fetch keyword, do you ?

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 9:51 am 
Newbie

Joined: Sun Nov 30, 2003 4:46 am
Posts: 17
Here is my code:

I have an Employee object which contains a collection of PhoneNumbers

Employee emp;
Iterator it = session.iterate("from Employee where id=6");

if(it.hasNext())
emp = (Employee)it.next();

System.out.println(Hibernate.isInitialized(emp.getPhoneNos()));

The last statement prints "true".

Even if both Employee and Phone were declared to have a proxy, then would the entire Phone (proxy) collection be initialized if Employee (proxy) was accessed like in the code above?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 15, 2003 10:21 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Declaring Phone as a proxyed class won't lazy load the collection but the objects contained in the collection.
Use <set lazy="true"> to lazy a collection

_________________
Emmanuel


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