HIbernate and eager loading of collections -


i have 1-many relationship between class a , class b, represented foreign key relation between 2 tables in database. , want hibernate eagerly load collection of bs can traversed outside session.

so specify lazy="false" on both one-to-many , many-to-one mapping entry.

b.hbm :

<many-to-one cascade="all" fetch="join" lazy="false"    class="a" name="...">    <column name="adgroup_id"/>   </many-to-one> 

a.hbm

<list cascade="all" inverse="true" name="..." lazy="false" fetch="join">       <key column="adgroup_id" />        <one-to-many class="b"  /> </list> 

i notice sql executed hibernate indeed returns expected number of rows, when call

a.getbs(), many elements. indeed, since ids in database auto-assigned, seems return n+1 elements n highest id in table of bs.

what going on here ?

i using spring hibernate template btw, calling template.get(class,id) return a

very description of n+1 problem: what select n+1?


Comments