Hi,
I am fetching a list that should return 8 elements but getting back a collection with 837 elements. 8 of those elements are the correct non-null instances and the rest are null elements.
The SQL looks right, the SQL runs in MSSQL with only 8 rows returned, so quite how 837 is getting into my collection I am unsure!
Hibernate version:
3.0
Mapping documents:
Code:
<list name="updates" inverse="true" lazy="true" cascade="all">
<key column="schedule_id" />
<index column="update_id" />
<one-to-many class="com.qas.newmedia.intranet.schedules.dto.ScheduleUpdate"/>
</list>
Code between sessionFactory.openSession() and session.close():We use the hibernate template in Spring.
Code:
Schedule schedule = (Schedule)
getHibernateTemplate().load(Schedule.class, id);
getHibernateTemplate().initialize(schedule.getUpdates());
for (ScheduleUpdate u : schedule.getUpdates()) {
logger.debug("update=" + u);
}
Full stack trace of any exception that occurs:None
Name and version of the database you are using:MSQL 2K
The generated SQL (show_sql=true):From this output, it's clear there is no problem with the SQL. I've run this in MSSQL with the update ID and it loads fine and the update count is in fact 8, not 837.
Code:
Hibernate: select schedule0_.schedule_id as schedule1_0_, schedule0_.owner as owner31_0_, schedule0_.associates as associates31_0_, schedule0_.status as status31_0_, schedule0_.title as title31_0_, schedule0_.summary as summary31_0_, schedule0_.created as created31_0_, schedule0_.last_updated as last9_31_0_, schedule0_.development_signoff as develop10_31_0_, schedule0_.development_signoff_format as develop11_31_0_, schedule0_.qat_signoff as qat12_31_0_, schedule0_.qat_signoff_format as qat13_31_0_, schedule0_.launch as launch31_0_, schedule0_.launch_format as launch15_31_0_, schedule0_.product_release as product16_31_0_, schedule0_.data_in_house as data17_31_0_, schedule0_.data_in_house_format as data18_31_0_, schedule0_.data_reviewed as data19_31_0_, schedule0_.data_reviewed_format as data20_31_0_, schedule0_.contract_reviewed as contract21_31_0_, schedule0_.contract_reviewed_format as contract22_31_0_, schedule0_.contract_signed as contract23_31_0_, schedule0_.contract_signed_format as contract24_31_0_, schedule0_.approval as approval31_0_, schedule0_.approval_format as approval26_31_0_, schedule0_.target_completion as target27_31_0_, schedule0_.target_completion_format as target28_31_0_, schedule0_.roi as roi31_0_, schedule0_.implementor as impleme30_31_0_, schedule0_.owning_department as owning31_31_0_, schedule0_.target_start as target32_31_0_, schedule0_.target_start_format as target33_31_0_, schedule0_.actual_start as actual34_31_0_, schedule0_.actual_start_format as actual35_31_0_, schedule0_.initial_completion as initial36_31_0_, schedule0_.initial_completion_format as initial37_31_0_, schedule0_.actual_completion as actual38_31_0_, schedule0_.actual_completion_format as actual39_31_0_, schedule0_.pm_score as pm40_31_0_, schedule0_.del_score as del41_31_0_, schedule0_.schedule_type as schedule2_0_ from dbSchedules.dbo.tbl_Schedules schedule0_ where schedule0_.schedule_id=?
Code:
Hibernate: select updates0_.schedule_id as schedule6___, updates0_.update_id as update1___, updates0_.update_id as update1_0_, updates0_.created as created34_0_, updates0_.author as author34_0_, updates0_.comment as comment34_0_, updates0_.internal as internal34_0_, updates0_.schedule_id as schedule6_34_0_ from dbSchedules.dbo.tbl_ScheduleUpdates updates0_ where updates0_.schedule_id=?
Debug level Hibernate log excerpt:Code:
2005-06-01 15:08:34,687 - DEBUG (org.hibernate.engine.TwoPhaseLoad:96) - resolving associations for [com.qas.newmedia.intranet.schedules.dto.ProductSchedule#494]
2005-06-01 15:08:34,687 - DEBUG (org.hibernate.engine.CollectionLoadContext:134) - creating collection wrapper:[com.qas.newmedia.intranet.schedules.dto.Schedule.milestones#494]
2005-06-01 15:08:34,702 - DEBUG (org.hibernate.engine.CollectionLoadContext:134) - creating collection wrapper:[com.qas.newmedia.intranet.schedules.dto.Schedule.updates#494]
2005-06-01 15:08:34,702 - DEBUG (org.hibernate.engine.CollectionLoadContext:134) - creating collection wrapper:[com.qas.newmedia.intranet.schedules.dto.Schedule.links#494]
2005-06-01 15:08:34,702 - DEBUG (org.hibernate.engine.CollectionLoadContext:134) - creating collection wrapper:[com.qas.newmedia.intranet.schedules.dto.Schedule.subscribers#494]
2005-06-01 15:08:34,702 - DEBUG (org.hibernate.engine.TwoPhaseLoad:167) - done materializing entity [com.qas.newmedia.intranet.schedules.dto.ProductSchedule#494]
2005-06-01 15:08:34,702 - DEBUG (org.hibernate.engine.PersistenceContext:738) - initializing non-lazy collections
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.loader.Loader:1278) - done entity load
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.event.def.DefaultInitializeCollectionEventListener:42) - initializing collection [com.qas.newmedia.intranet.schedules.dto.Schedule.updates#494]
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.event.def.DefaultInitializeCollectionEventListener:47) - checking second-level cache
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.event.def.DefaultInitializeCollectionEventListener:59) - collection not cached
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.loader.Loader:1336) - batch loading collection: [com.qas.newmedia.intranet.schedules.dto.Schedule.updates#494]
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.jdbc.AbstractBatcher:258) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.jdbc.AbstractBatcher:343) - preparing statement
2005-06-01 15:08:34,718 - DEBUG (org.hibernate.type.NullableType:59) - binding '494' to parameter: 1
2005-06-01 15:08:34,734 - DEBUG (org.hibernate.jdbc.AbstractBatcher:274) - about to open ResultSet (open ResultSets: 0, globally: 0)
2005-06-01 15:08:34,734 - DEBUG (org.hibernate.loader.Loader:610) - result set contains (possibly empty) collection: [com.qas.newmedia.intranet.schedules.dto.Schedule.updates#494]
2005-06-01 15:08:34,734 - DEBUG (org.hibernate.engine.CollectionLoadContext:78) - uninitialized collection: initializing
2005-06-01 15:08:34,734 - DEBUG (org.hibernate.loader.Loader:377) - processing result set
2005-06-01 15:08:34,749 - DEBUG (org.hibernate.loader.Loader:382) - result set row: 0
2005-06-01 15:08:34,749 - DEBUG (org.hibernate.type.NullableType:86) - returning '807' as column: update1_0_
and so on until row 8
Code:
2005-06-01 15:08:34,905 - DEBUG (org.hibernate.jdbc.AbstractBatcher:363) - closing statement
2005-06-01 15:08:34,905 - DEBUG (org.hibernate.loader.Loader:450) - total objects hydrated: 8