Join Fetch: "query specified join fetching, but the owner of the fetched association was

折月煮酒 提交于 2019-12-23 07:36:58

问题


I have the following Model Activity with the language-depending property Title. The language-dependency is defined with two additional entities Translation (Title is of this type, many-to-one) and TranslationValue (one-to-many).

If I write the following hql:

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

This works fine so far. But as soon as I add act into the select-statement, I've got a problem with the join of 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

I can't figure out why Hibernate doesn't like that!?

Thx for any tipps!


回答1:


... turns out that I need to define an alias for the first join. This does the trick (notice alias title):

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


来源:https://stackoverflow.com/questions/5404270/join-fetch-query-specified-join-fetching-but-the-owner-of-the-fetched-associa

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!