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