Hi
I was following the examples in the 'Java Persistence and Hibernate' book with Hibernate 3.3.1 to try and load my collection upfront using fetch=join as follows:
Code:
<!-- Parent class -->
<hibernate-mapping>
<class name="Person" table="PERSON">
...
<set name="telephones" fetch="join" cascade="all-delete-orphan">
<key column="PERSON_FK"/>
<one-to-many class="Telephone"/>
</set>
...
</hibernate-mapping>
<!-- Child collection class -->
<hibernate-mapping>
<class name="Telephone" table="TELEPHONE">
...
<property name="telNumber" column="TELNUMBER"/>
</class>
</hibernate-mapping>
I would expect that when I do a session.get(Person.class, personId), that I would automatically fetch any associated Telephones and would not have to do e.g.
Hibernate.initialise(person.getTelephones).
However, the collection is not being fetched.
I tried putting lazy="false" in with fetch="join" and all that seemed to happen was an n+1 selects generated (which I want to avoid).
Any ideas?
thanks, Baljeet.