hibernate中的lazy load还真麻烦

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值