Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

hql

nhibernate

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!

like image 809
sl3dg3 Avatar asked Mar 23 '11 11:03

sl3dg3


1 Answers

... 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
like image 99
sl3dg3 Avatar answered Nov 15 '22 12:11

sl3dg3