-->
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: Collection can't be lazy
PostPosted: Thu Mar 01, 2007 10:31 am 
Beginner
Beginner

Joined: Sun Jul 31, 2005 6:15 pm
Posts: 28
Hi All,

It's about one day I'm struggling with this problem without understanding what's going on

I'm on mysql5 using hibernate 3, using all the default conf

here is my mapping file for the work object


<hibernate-mapping package="model">

<class name="model.Work" table="work" lazy="true" batch-size="30" >

<id name="id" column="id">
<generator class="native"/>
</id>

<property name="salary" />

</class>

</hibernate-mapping>



but when I call


List l = session.createQuery("From Work").list();


All the table is loaded !!!!

The log end with

StatefulPersistenceContext:748 - initializing non-lazy collections


Can someone give me a hint I really can't figure out what's going on.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 12:02 pm 
Newbie

Joined: Fri Nov 17, 2006 5:18 pm
Posts: 4
Location: Quilmes, Argentina
You don't understand what lazy initialization is. It's a feature for mapped collections, not for list of mapped classes. You get exactly what are you asking in the query: a list of all Work instances.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 12:49 pm 
Beginner
Beginner

Joined: Sun Jul 31, 2005 6:15 pm
Posts: 28
Well,

I probably miss explain myself, when you query a collection of object using

session.createQuery("From Something).list();

hibernate should not load all the resultSet in the collection, imagine you have 1 million of lines....

It's here the batch size become important, but as you can see in my previous post, setting the batch size don't change anything.

Thanks anyway


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 01, 2007 1:55 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
For what you are trying to achieve use the following.

Query q = session.createQuery("From Something");
q.setFirstResult(n);
q.setMaxResults(30);
List l = q.list();

batch-size is a different concept.


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.