Many many-to-one for one table

I have a product table with two many-to-one links (name and description) in one table called TextRef:

Product:

<many-to-one lazy="false" name="Title" class="TextRef" column="TitleRef" fetch="join" cascade="save-update"/>
<many-to-one lazy="false" name="Description" class="TextRef"  column="DescriptionRef" fetch="join" cascade="save-update"/>

each TextRef has a one-to-many table in TextRefItem:

<bag lazy="false" name="Values" table="TextRefItem" cascade="save-update" inverse="true" fetch="join">
  <key column="TextId"></key>
  <one-to-many class="TextRefItem"/>
</bag>

now I want to load all TextRefItem for the title and description at a time, but NHibernate only creates a connection to the first link (Title)

SELECT this_.ProductId as ProductId7_2_, this_.CategoryId as CategoryId7_2_, 
this_.DescriptionRef as Descript3_7_2_,
textref2_.TextId as TextId8_0_, values3_.TextId as TextId4_, 
values3_.TextItemId as TextItemId4_, values3_.TextItemId as TextItemId9_1_,values3_.LangId as LangId9_1_,
values3_.Text as Text9_1_, values3_.TextId as TextId9_1_ 
FROM
Product this_
inner join TextRef textref2_ on this_.DescriptionRef=textref2_.TextId
left outer join TextRefItem values3_ on textref2_.TextId=values3_.TextId
WHERE this_.ProductId = 1

for another (description) he makes a separate selection request

How can I tell NHibernate to avoid this?

+3
source share
1 answer

, (). , TextRefs TextRefItems :

var criteria = session.CreateCriteria(typeof(Product))
   .SetFetchMode("Description.Values", FetchMode.Join);

criteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
criteria.Add(Restrictions.Eq("ProdId", 1));
var list = criteria.List<Product>();
+1

All Articles