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.  [ 2 posts ] 
Author Message
 Post subject: Iterator breaks lazy mechanism
PostPosted: Mon Oct 17, 2005 6:25 am 
Newbie

Joined: Fri Jun 03, 2005 12:14 pm
Posts: 4
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Calling iterator on a collection causes hibernate to load everything in the collection even if only the first element is accessed, as if lazy is set to false.
Here is the code that causes this :

public String getLocation() {
if(reservations != null){
Iterator it = this.reservations.iterator(); <----- hibernate loads everything on this instruction
if(it.hasNext()){
ReservationVO reservation = (ReservationVO) it.next();
FieldVO field = (FieldVO) reservation.getResource();
if(field.isInnerField())
return field.getParentField().getName();
else
return field.getName();
}else{
log.warn("getLocation : no reservation found for trainingSession with id : " + this.getId());
return null;
}
}else{
log.warn("getLocation : reservation is null for trainingSession with id : " + this.getId());
return null;
}
}


And here is my mapping document :

<joined-subclass name="fr.ippon.logsport.model.TrainingSessionVO" table="_training_session">
<key column="ID"/>
<property name="allDay" column="ALL_DAY"/>
<property name="weeklyRepeated" column="WEEKLY_REPEATED"/>
<set lazy="true" cascade="all-delete-orphan" name="weeksNotRepeated">
<key column="TRAINING_SESSION_ID"/>
<one-to-many class="fr.ippon.logsport.model.CalendarWrapperVO"/>
</set>
<set table="_trainingsession_trainingparticipant" lazy="true" cascade="all" name="trainingParticipants">
<key column="TRAINING_SESSION_ID"/>
<many-to-many column="TRAINING_PARTICIPANT_ID" class="fr.ippon.logsport.model.TrainingParticipantVO"/>
</set>
<many-to-one column="TRAINING_GROUP_ID" name="trainingGroup" class="fr.ippon.logsport.model.TrainingGroupVO"/>
<set lazy="true" cascade="all-delete-orphan" name="reservations">
<key column="TRAINING_SESSION_ID"/>
<one-to-many class="fr.ippon.logsport.model.ReservationVO"/>
</set>
</joined-subclass>

This is not the only place that this happens in my application. I've noticed it in many locations causing the app to be much slower than it should be.
Anybody already experienced this or has a clue to what is going on when iterator is invoqued?



Arthur


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 11:38 am 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
This is working as designed, accessing a collection will initialize it, in the iterator case:

Code:
   public Iterator iterator() {
      read();
      return new IteratorProxy( set.iterator() );
   }


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