Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 26th, 2012  |  syntax: None  |  size: 1.24 KB  |  hits: 7  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Multiple many-to-one to a single table
  2. <many-to-one lazy="false" name="Title" class="TextRef" column="TitleRef" fetch="join" cascade="save-update"/>
  3. <many-to-one lazy="false" name="Description" class="TextRef"  column="DescriptionRef" fetch="join" cascade="save-update"/>
  4.        
  5. <bag lazy="false" name="Values" table="TextRefItem" cascade="save-update" inverse="true" fetch="join">
  6.   <key column="TextId"></key>
  7.   <one-to-many class="TextRefItem"/>
  8. </bag>
  9.        
  10. SELECT this_.ProductId as ProductId7_2_, this_.CategoryId as CategoryId7_2_,
  11. this_.DescriptionRef as Descript3_7_2_,
  12. textref2_.TextId as TextId8_0_, values3_.TextId as TextId4_,
  13. values3_.TextItemId as TextItemId4_, values3_.TextItemId as TextItemId9_1_,values3_.LangId as LangId9_1_,
  14. values3_.Text as Text9_1_, values3_.TextId as TextId9_1_
  15. FROM
  16. Product this_
  17. inner join TextRef textref2_ on this_.DescriptionRef=textref2_.TextId
  18. left outer join TextRefItem values3_ on textref2_.TextId=values3_.TextId
  19. WHERE this_.ProductId = 1
  20.        
  21. var criteria = session.CreateCriteria(typeof(Product))
  22.    .SetFetchMode("Description.Values", FetchMode.Join);
  23.  
  24. criteria.SetResultTransformer(new DistinctRootEntityResultTransformer());
  25. criteria.Add(Restrictions.Eq("ProdId", 1));
  26. var list = criteria.List<Product>();