延迟加载一对一休眠 [英] Lazy load nhibernate one-to-one

查看:98
本文介绍了延迟加载一对一休眠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个真正的一对一映射.但是我想使用延迟加载(按需加载).

I have a true one to one mapping. But I would like to use lazy loading(load on demand).

我有与班级地址"相关联的班级人员.映射看起来像这样.

I have Class Person with a association with Class Address. The mapping looks like this..

PERSON

<one-to-one name="address" class="Person" cascade="all-delete-orphan" access="field">

地址

<class name="Address" table="Address" lazy="true">
<id name="id" column="addressId" type="Int32" access="field">
  <generator class="foreign">
    <param name="property">person</param>
  </generator>      
</id>
<one-to-one name="person" class="Address" constrained="true" access="field" />

有人看到这有什么问题吗?如何为地址启用代理/延迟加载?

Does anyone see something wrong with this? How do I enable proxy/lazy loading for address?

谢谢

推荐答案

此处对关键语录:换句话说,不能延迟加载一对一,这是建议使用两个多对一的原因之一."

Crucial quote: "In other words, one-to-one cannot be lazily loaded, which is one of the reasons why it is recommended to use two many-to-one instead."

另请参见 https://www.hibernate.org/162.html NHibernate:如何在单机上启用延迟加载-一个映射

这篇关于延迟加载一对一休眠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆