I using 3.0.1 on MS Sql Server and have some many-to-one associations in my class that I can't get to lazy load.
Code:
<class
name="au.edu.nd.teachingprac.domain.PracRecord"
table="SPTP"
dynamic-update="false"
dynamic-insert="false"
lazy="true"
>
<cache usage="read-write" />
...
<many-to-one
name="studentMark"
class="au.edu.nd.teachingprac.domain.StudentMarks"
cascade="none"/
outer-join="auto"
update="false"
insert="false"
access="property"
property-ref="pracMark"
>
<column name="skey" />
<column name="Ttperiod" />
<column name="mkey" />
</many-to-one>
...
</class>
<class
name="au.edu.nd.teachingprac.domain.StudentMarks"
table="STMA"
dynamic-update="false"
dynamic-insert="false"
lazy="true"
>
<cache usage="read-only" />
...
<!-- unique key -->
<component
name="pracMark"
class="au.edu.nd.teachingprac.domain.PracMark"
>
<property
name="studentKey"
type="java.lang.String"
update="false"
insert="false"
access="property"
column="skey"
/>
<property
name="ttperiod"
type="java.lang.String"
update="false"
insert="false"
access="property"
column="ttperiod"
/>
<property
name="subject"
type="java.lang.String"
update="false"
insert="false"
access="property"
column="mkey"
/>
</component>
...
</class>
Any access, eg session.get(PracRecord.class, 786) or queries returning PracRecord's will trigger an additional select to load the StudentMark for each PracRecord. I thought maybe because the component class, PracMark, can't(?maybe im wrong here) be marked as lazy and proxied like a top level class can, it's the cause of the problem.
Any ideas what I'm doing wrong? or if im going about this the wrong way. I had tried doing it using a <properties> element instead of a component, but that approach wasn't right as I would get classcast exceptions in the depths of hibernate.