This is an important addition, especially to solve performance problems, allowing you to write efficient dynamic HQL queries.
But how can we change the HQL transformer when loading a specific parent or other property of the associated object?
The following code:
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 only some of the properties of his parents?
For example, let's say SomeTable has a parent called SomedParent , and I want to access only one of the fields of this parent?
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();
So any ideas?
hibernate hql
source share