問題我已經有很多ClassB的元素ClassA的:NHibernate的 - 與預先加載
public abstract class ClassA: IEntity<ClassA>
{
public virtual IList<ClassB> ClassBList { get; protected set; }
...
}
然後ClassB的引用ClassC元素:
public class ClassB
{
public ClassC CEntity { get; private set; }
public Percentage Percentage{ get; private set; }
...
}
這裏是ClassA的映射(ClassB的無映射):
HasMany(a => a.ClassBList).Component(a =>
{
a.References(b => b.CEntity , "IDCEntity").ForeignKey("ID").Cascade.SaveUpdate().Not.LazyLoad();
t.Map(b => b.Percentage, "Percentage");
...;
}).AsBag().Cascade.AllDeleteOrphan().Not.LazyLoad()
當我從數據庫中獲取所有classA元素時,它將ClassBi中的所有ClassB st加載,但它不會加載ClassB中的ClassC元素。
我嘗試以下HQL:
var query = session.CreateQuery("select a from ClassA as a left join fetch a.ClassBList as b left join fetch b.CEntity as c");
classAList = query.List<ClassA>();
,但我得到這個錯誤:
Exception = {"Query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=c,role=,tableName=ClassCTable,tableAlias=classc2_,or...
我想這是因爲我試圖CLASSB的渴望負荷ClassC元素,但CLASSB是不在hte選擇列表中。
什麼是替代方案,或正確的HQL?
注:我不能使用,因爲this問題的標準:如果問題通過複雜的關聯,跨越3個實體是急於負載