仅在必要时加载对象

本文关键字:加载 对象 | 更新日期: 2023-09-27 18:30:55

我有一个Slab对象的映射,其中包含对对象和SlabPDOSlabInstructions的映射引用。我想做选择,总是携带对象SlabPDO并仅在必要时加载SlabInstructions。有什么办法可以做到这一点吗?下面是映射示例:

<id name="Id" column="Id_Slab" type="Int64">
  <generator class="Geraes.GLib.GDomainBasis.CustomTableHiLoGenerator, GLib.GDomainBasis" />
</id>
<property name="Mill" column="Mill" type="String" length="2" not-null="true" />
<property name="SlabId" column="Slab_Id" type="String" length="20" not-null="true" />
<property name="PieceId" column="Piece_Id" type="String" length="20" not-null="true" />
<one-to-one name="SlabPDO" class="SlabPDO" cascade="all" fetch="join"/>
<set name="SlabInstructions" generic="true" inverse="true" lazy="false" cascade="all" fetch="join">
  <key column="Id_Slab" />
  <one-to-many class="SlabInstruction"/>
</set>

此致敬意!

仅在必要时加载对象

关于这两个映射属性lazy="true" fetch="select"查阅文档 http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/performance.html#performance-fetching

这是您的解决方案

<set name="SlabInstructions" generic="true" inverse="true" lazy="true" cascade="all"
  fetch="select">
  <key column="Id_Slab" />
  <one-to-many class="SlabInstruction"/>
</set>