I am using Spring's HibernateDaoSupport class. My code is
Code:
getHibernateTemplate().find("from MyBean as mybean where mybean.prop=?",myprop).get(0);
As I am not using lazy initialisation, the set is fetched as soon as I fetch the object and a select statement is issued for each one of its elements. I forgot to precise a point :
The class of the elements of the set has a composite id. One of the columns composing the id is the same column I am using in the <key> of the set :
Code:
<class name="MyElement">
<composite-id>
<key-property name="id" type="long"/>
<key-property name="id2" type="string"/>
</composite-id>
</class>
<class name="MyBean">
<id name="id" type="long">
<generator class="assigned"/>
</id>
<set name="mySet" outer-join="true">
<key column="id"/>
<one-to-many class="MyElement"/>
</set>
</class>