Using hibernate 3.6.0.Final I noticed the following problem.
If I have a query defined like this:
Code:
<sql-query name="myQuery1" >
<return alias="st" class="Star">
<return-property name="id" column="key_one" />
<return-property name="name" column="nick" />
<return-property name="mass" column="pounds" />
</return>
<return-join alias="wp" property="st.planets">
<return-property name="id" column="ignored_by_hibernate"/>
<!-- <return-property name="id" column="also_ignored"/>-->
<return-property name="myStar" column="I can write whatever I want here"/>
</return-join>
select
st.id as key_one,
st.name as nick,
st.mass as pounds ,
wp.my_star_id as my4_1_0__,
wp.id as id0__,
wp.id as id2_1_,
... (rest is below)
It appears the return-property tags inside the return-join tag are not recognized. No matter what values I put for name or column, hibernate will use its own values form column names, like id0_ , id2_1_, etc.
I discovered that in <return> if I misspell a name, like this: <return-property name="ifoood" column="key_one" />
then hibernate will use a column name like "id1_0_" for that column.
So I guess I have the name attributes wrong in the return-join tag.
I tried "id", "wp.id", "st.wp.id", but nothing is recognized.
Any idea what is wrong?
Here is the mapping:
Code:
<class name="Star" table="STARS">
<id name="id" column="id"><generator class="sequence"/></id>
<property name="name"/>
<property name="mass"/>
<set name="planets" inverse="true">
<key column="my_star_id" />
<one-to-many class="Planet" />
<loader query-ref="customLoader"/>
</set>
</class>
<class name="Planet">
<id name="id" column="id"><generator class="sequence"/></id>
<property name="name"/>
<many-to-one name="myStar" column="my_star_id"/>
</class>
The complete SQL in above named query is:
Code:
select
st.id as key_one,
st.name as nick,
st.mass as pounds ,
wp.my_star_id as my4_1_0__,
wp.id as id0__,
wp.id as id2_1_,
wp.name as name2_1_,
wp.my_star_id as my4_2_1_
from
STARS st
left outer join
Planet wp
on st.id=wp.my_star_id
where
st.name like :namePattern