Hi,
I want to select an entity and a single element from a collection of elements that is contained in the entity.
I'm currently doing something like this:
Code:
select theme, text.name from ThemeEntity theme left outer join theme.translations as text with index(text)=:languageCode where theme.uid=:themeUid order by theme.index asc
or
Code:
select theme, new <somepackage>.ThemeText(text.name) from ThemeEntity theme left outer join theme.translations as text with index(text)=:languageCode where theme.uid=:themeUid order by theme.index asc
This works if the elements have only a few attributes. If there are more attributes, selecting all of them explicitly is quite cumbersome, even more so if I want to improve type safety by using the constructor syntax.
Now, my question is: Is there a way to query a single element from a collection of elements and make Hibernate initialize it automatically?
Obviously "select entity, element ..." doesn't work since this is translated into something like "select ... from TaElement element where element.id = ?" and there's no id column in TaElement.
Thanks in advance.
Thomas