views:

2269

answers:

0

This is a important addition especially to solve performance issues while being able to write efficient dynamic HQL queries. But, how do we modify the HQL transformer in case of loading a specific parent or another mapped entity property.

session.createQuery(
"select st.stNumber as stNumber, st.stDate as stDate "
+ " from SomeTable st "
+ " where st.someTableId < 1000")
.setResultTransformer( Transformers.aliasToBean(database.SomeTable.class))
.list();

works fine but what if I want to load some of its parents properties only, as lets say, SomeTable has a parent called SomedParent and I want to access one of the fields of this parent only

session.createQuery(
"select st.stNumber as stNumber, st.stDate as stDate, st.someParent.someParentField as someParentField "
+ " from SomeTable st "
+ " where st.someTableId < 1000")
.setResultTransformer( Transformers.aliasToBean(database.SomeTable.class))
.list();

This fails, so any ideas?