-->
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.  [ 6 posts ] 
Author Message
 Post subject: Will hibernate fetch all the objects into memory ?
PostPosted: Wed Aug 27, 2003 2:59 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 11:33 pm
Posts: 38
I have a large table which contains millions of records. I code the following method to randomly get certain record:

public Item getNthItem(Session session, int nth) throws HibernateException {
Query q = session.createQuery("from hibernate.Item");
List list = q.list();
return (Item) list.get(nth);
}

Will q.list() fetch all the objects that matched into memory ? Or fetch them one by one when list.get(nth) is executed ? What I want is the latter situation. Who could tell me if it is okay or not?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 3:06 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
If you want the latter, you must use iterate() or scroll(), together with Session.evict() or Session.clear().


Top
 Profile  
 
 Post subject: Isn't there a way to control cached objects automatically ?
PostPosted: Wed Aug 27, 2003 3:11 am 
Beginner
Beginner

Joined: Tue Aug 26, 2003 11:33 pm
Posts: 38
Is there some config to limit number of cached objects ? I mean not running into OutOfMemoryException without calling evict () manually.


Top
 Profile  
 
 Post subject: lazy loading
PostPosted: Wed Aug 27, 2003 4:39 am 
Newbie

Joined: Wed Aug 27, 2003 1:37 am
Posts: 10
Location: Kyrgyzstan
If I am not mistaken the lazy paramater of a collection mapping will produce the desired behavior when set to true. For example, when you use the following mapping the collection returned by the getLocalizedStrings method will load objects from the database only as needed.

<set name="localizedStrings" cascade="all" inverse="true" lazy="true">
<key column="stringCollection"/>
<one-to-many class="com.atwoodsoft.data.LocalizedString"/>
</set>


Top
 Profile  
 
 Post subject: Re: lazy loading
PostPosted: Wed Aug 27, 2003 10:28 am 
Newbie

Joined: Tue Aug 26, 2003 9:45 am
Posts: 17
Location: Toronto, Canada
JohnDoeKyrgyz wrote:
If I am not mistaken the lazy paramater of a collection mapping will produce the desired behavior when set to true. For example, when you use the following mapping the collection returned by the getLocalizedStrings method will load objects from the database only as needed.


No, the lazy setting on a collection only makes Hibernate be lazy about loading the entire collection. That is, it will only load the (entire) collection when you first try to do an operation on it, as opposed to when the entity containing the collection is loaded...


Top
 Profile  
 
 Post subject: Re: Will hibernate fetch all the objects into memory ?
PostPosted: Wed Oct 13, 2010 5:30 am 
Newbie

Joined: Wed Oct 13, 2010 5:25 am
Posts: 10
I spent my whole life trying not to be careless. Women and children can be careless. But not men.

_________________
cheap watches
replica watches uk
replica watches


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