To lazily load a related class, you must configure the <many-to-one> or <oneto-
one> association element that references the class to use lazy loading. You
must also disable proxying for the referenced class. For example, you can lazily
load a PendingOrder’s coupon by configuring the PendingOrder’s coupon property
with lazy="true". Here is an excerpt from the O/R mapping document for the
PendingOrder and Coupon classes that does this:
<class name="PendingOrder" table="PENDING_ORDER">
…
<many-to-one name="coupon"
class="AbstractCouponImpl"
column="COUPON_ID"
[color=red][b]lazy="true"
fetch="select"[/b][/color]
/>
…
</class>
<class name="AbstractCouponImpl"
[b][color=red]lazy="false"[/color][/b]
table="COUPON">
…
[color=blue][b]The lazy="true" attribute of the <many-to-one> element specifies that the coupon
property should only be loaded when it is first accessed. The fetch="select" prevents
Hibernate from eagerly loading the Coupon using an outer join. The
lazy="false" attribute of the <class> element for the AbstractCouponImpl class
tells Hibernate to not use a proxy for this class.[/b][/color]
in pojo in action (on page 244)
one> association element that references the class to use lazy loading. You
must also disable proxying for the referenced class. For example, you can lazily
load a PendingOrder’s coupon by configuring the PendingOrder’s coupon property
with lazy="true". Here is an excerpt from the O/R mapping document for the
PendingOrder and Coupon classes that does this:
<class name="PendingOrder" table="PENDING_ORDER">
…
<many-to-one name="coupon"
class="AbstractCouponImpl"
column="COUPON_ID"
[color=red][b]lazy="true"
fetch="select"[/b][/color]
/>
…
</class>
<class name="AbstractCouponImpl"
[b][color=red]lazy="false"[/color][/b]
table="COUPON">
…
[color=blue][b]The lazy="true" attribute of the <many-to-one> element specifies that the coupon
property should only be loaded when it is first accessed. The fetch="select" prevents
Hibernate from eagerly loading the Coupon using an outer join. The
lazy="false" attribute of the <class> element for the AbstractCouponImpl class
tells Hibernate to not use a proxy for this class.[/b][/color]
in pojo in action (on page 244)