2012-04-11 52 views
0

我有一个Slab对象的映射,它具有对对象和SlabPDO SlabInstructions的映射引用。我想做选择,总是携带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> 

祝商祺!

+1

您可以将标题翻译成英文请。 – ChrisF 2012-04-11 10:32:17

回答

0

关于这两个映射属性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> 
+0

感谢您的回复! 问题是,在90%的情况下,将需要子对象。在其他情况下,我是否需要放弃加载子对象。最好的方法是什么? – 2012-04-11 18:56:31

+1

当您编写查询时,您可以指定加载子对象('left join fetch')。所以映射可以是懒惰的,以保存10%的情况下不必要的子对象加载。 – bpgergo 2012-04-12 14:19:23