Hibernate version: 3.1
Mapping documents:
state mapping
Code:
<set name="counties" inverse="true">
<key>
<column name="STATE_CODE" length="2" not-null="true" />
</key>
<one-to-many class="com.County" />
</set>
county mapping
Code:
<many-to-one name="state" class="com.State" update="false" insert="false">
<column name="STATE_CODE" length="2" not-null="true" />
</many-to-one>
Code between sessionFactory.openSession() and session.close():Code:
List results = SessionFactory.currentSession().createQuery("FROM State s join fetch s.counties WHERE s.stateCode = '42'").list();
System.out.println(results.size());
Full stack trace of any exception that occurs:
NA
Name and version of the database you are using:
MySQL
The generated SQL (show_sql=true):
NA
Debug level Hibernate log excerpt:
NA
How come when ever I use the follwing query I get 277 State objects returned in the list ...
"FROM VsiState s join fetch s.vsiCounties WHERE s.stateCode = '42'"
but when I use this query..
"FROM VsiState WHERE s.stateCode = '42'"
I get what I expect, one State. From my understanding joing fetch tells hibernate to eagerly retrieve the counites instead of the default lazy fetching defined in the mapping file. So, my question is ... why is join fetch causing Hibernate to return 277 State objects when all I want is one State object with its counties already (eagerly) fetch.? How do I fix this?
Thanks for any help :)