加入提取:“查询指定加入提取,但获取的关联的所有者为 [英] Join Fetch: "query specified join fetching, but the owner of the fetched association was
问题描述
我有以下带有语言相关属性Title
的模型Activity
.语言依赖性由另外两个实体Translation
(标题是这种类型,多对一)和TranslationValue
(一对多)定义.
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).
如果我写以下hql:
from Activity act join fetch act.Title join fetch act.Title.TranslationValuesSet
到目前为止,这个方法工作正常.但是,一旦我将行为添加到选择语句中,我就对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
我不知道为什么Hibernate不喜欢那样!!
I can't figure out why Hibernate doesn't like that!?
感谢小费!
推荐答案
...原来,我需要为第一个联接定义一个别名.这样就可以了(注意别名title
):
... 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
这篇关于加入提取:“查询指定加入提取,但获取的关联的所有者为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!