5
我有一个复合组件,它具有多对一的参考。如何避免“N + 1选择”并指定具有多对一的(N)Hibernate用户类型的获取策略?
class MyComposite
{
SomeEntity ManyToOne { get; set; }
SomeOtherUserType Value { get; set; }
}
为了便于测绘的,我做了一个自定义的ICompositeUserType
其encompases这个组件:
class MyCompositeUserType : ICompositeUserType
{
// ...
private static readonly IType[] _propertyTypes = new[]
{
new ManyToOneType("SomeEntity"),
new CustomType(typeof(SomeOtherUserType))
};
// ...
}
现在,我的composite-element
S的包括该组件的集合:
<class name="Container">
...
<set name="Pairings"
cascade="all-delete-orphan"
generic="true"
lazy="false"
table="Pairings"
fetch="join">
<key column="ContainerId" />
<composite-element class="Pair">
<property name="Item1" type="mycomposite" lazy="false">
<column name="Entity1Id" />
<column name="Amount1" />
</property>
<property name="Item2" type="mycomposite" lazy="false">
<column name="Entity2Id" />
<column name="Amount2" />
</property>
<property name="Tag" column="Tag" />
</composite-element>
</set>
</class>
当我在Container
类上查询时,Pairings
集被急切加载,因为设计但是,然后,我在SomeEntity
上选择了一个N + 1,它构成MyCompositeUserType
的一部分。我想要在Pairings
集合上加载这些实体以及连接。
这怎么指定?
当它映射到一个或它应该是可以设置fetchmode?你是否指定了一个Fetch来加载相关的实体?如果是的话,那么你使用转换器来删除重复的根元素? – cdmdotnet 2012-05-01 21:30:52
对查询没有多余的提取。这仅仅是一个ToList。 – codekaizen 2012-05-01 21:42:27
是否有原因需要'ICompositeUserType'而不是''映射? –
Firo
2012-05-08 09:01:09