加入Fetch:“查询指定的连接提取,但获取的关联的所有者是

时间:2011-03-23 11:06:15

标签: nhibernate hql

我有以下模型Activity,其中包含依赖于语言的属性Title。语言依赖性由两个额外的实体Translation(标题属于此类型,多对一)和TranslationValue(一对多)定义。

如果我写下面的hql:

from Activity act join fetch act.Title join fetch act.Title.TranslationValuesSet

到目前为止,此工作正常。但是只要我在select语句中添加了act,我就遇到了TranslationValuesSet连接的问题:

select act from Activity act join fetch act.Title join fetch act.Title.TranslationValuesSet

NHibernate.QueryException: 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=,role=Translation.TranslationValuesSet,tableName=TranslationValue,tableAlias=translatio3_,origin=Translation translatio2_,colums={translatio2_.TranslationId ,className=TranslationValue}}] [select act from Activity act join fetch act.Title join fetch act.Title.TranslationValuesSet

我无法弄清楚为什么Hibernate不喜欢它??

任何tipps的Thx!

1 个答案:

答案 0 :(得分:9)

...事实证明我需要为第一个连接定义一个别名。这样做(通知别名title):

select act from Activity act join fetch act.Title title join fetch title.TranslationValuesSet