Hi all,
I think this has been discussed but Im still finding it confusing. (Newbie ;-)) I'm trying to map data from an account table and an assicated country table where the account table has a foreign key called country_id. I want to place all the data in the same pojo. The manula suggests using a join in this situation. However the join refuses to see the countryId field on the account and generates sql which looks at the account_id instead.
Reading this forum it seems to be a non-implemented feature which has crept into the distribution. I.e. it's in all the doco but the code has not been written and is listed in the source as TODO (although I cannot find the place in the source at the moment where this apparently is documented).
I'm wondering if anyone has an update or can provide me with a workaround. I beleive it can be done with a many-to-one but I'm just learning and don't understand how to do it as the many-to-one doco seems to indicate you need two classes.
Setup is as per below.
Thanks
Derek
Hibernate version: 3.1
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.lp.commissions.beans.Account" table="account" mutable="false">
<cache usage="read-only" />
<id name="accountId" column="account_id">
<generator class="native" />
</id>
<property name="name" type="string" column="account_name" />
<property name="countryId" access="field" type="integer" column="country_id" />
<!-- Join to get country and office information -->
<join table="country">
<key column="country_id" property-ref="countryId" />
<property name="officeId" column="office_id" />
<property name="countryName" column="name" />
</join>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): Not relevant
Full stack trace of any exception that occurs: No Exception occurs
Name and version of the database you are using: Postgres 7.3
The generated SQL (show_sql=true):
select this_.account_id as account1_0_0_,
this_.account_name as account2_0_0_,
this_.country_id as country3_0_0_,
this_1_.office_id as office2_1_0_,
this_1_.name as name1_0_
from account this_
inner join country this_1_ on
this_.account_id=this_1_.country_id
where this_.account_id = ? order by this_.account_id asc
Debug level Hibernate log excerpt: none relevant.