Hibernate version: 2.1.3
Mapping documents:
Code:
<class
name="employeeclub.domain.Activity"
table="activity"
>
<id
name="id"
type="long"
column="id"
>
<generator class="net.sf.hibernate.id.TableHiLoGenerator">
<param name="table">activity_seq</param>
<param name="column">next_hi</param>
<param name="max_lo">1</param>
</generator>
</id>
<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="255"
/>
<property
name="description"
type="java.lang.String"
column="description"
length="255"
/>
<!-- associations -->
<!-- bi-directional one-to-one association to ActivityTicket -->
<one-to-one
name="activityTicket"
class="employeeclub.domain.ActivityTicket"
outer-join="false"
cascade="all"
/>
</class>
<subclass name="employeeclub.domain.ActivityTicket" extends="employeeclub.domain.Item" discriminator-value="ACTIVITY_TICKET">
<!-- bi-directional many-to-one association to Activity -->
<many-to-one
name="activity"
class="employeeclub.domain.Activity"
unique="true"
>
<column name="detail_id" />
</many-to-one>
</subclass>
<subclass name="employeeclub.domain.Ticket" extends="employeeclub.domain.Item"/>
<class
name="employeeclub.domain.Item"
table="item"
polymorphism="implicit"
discriminator-value="not null"
>
<id
name="id"
type="long"
column="id"
>
<generator class="net.sf.hibernate.id.TableHiLoGenerator">
<param name="table">item_seq</param>
<param name="column">next_hi</param>
<param name="max_lo">1</param>
</generator>
</id>
<discriminator
column="type_id"
type="java.lang.String"
/>
<property
name="name"
type="java.lang.String"
column="name"
not-null="true"
length="255"
/>
<property
name="listPrice"
type="employeeclub.dao.hibernate.type.MoneyType"
column="list_price"
not-null="true"
length="19"
/>
<property
name="unitCost"
type="employeeclub.dao.hibernate.type.MoneyType"
column="unit_cost"
not-null="true"
length="19"
/>
<property
name="description"
type="java.lang.String"
column="description"
not-null="true"
length="255"
/>
<property
name="quantity"
type="int"
column="quantity"
not-null="true"
length="4"
/>
</class>
Code between sessionFactory.openSession() and session.close(): Using Spring
Full stack trace of any exception that occurs: N/A
Name and version of the database you are using: MSSQL 2k
The generated SQL (show_sql=true): Hibernate: select activity0_.id as id1_, activity0_.name as name1_, activity0_.description as descript3_1_, activityti1_.id as id0_, activityti1_.detail_id as detail_id0_, activityti1_.name as name0_, activityti1_.list_price as list_price0_, activityti1_.unit_cost as unit_cost0_, activityti1_.description as descript6_0_, activityti1_.quantity as quantity0_ from activity activity0_ left outer join item activityti1_ on activity0_.id=activityti1_.id where activity0_.id=?
Debug level Hibernate log excerpt:
The sql statement should be:
Hibernate: select activity0_.id as id1_, activity0_.name as name1_, activity0_.description as descript3_1_, activityti1_.id as id0_, activityti1_.detail_id as detail_id0_, activityti1_.name as name0_, activityti1_.list_price as list_price0_, activityti1_.unit_cost as unit_cost0_, activityti1_.description as descript6_0_, activityti1_.quantity as quantity0_ from activity activity0_ left outer join item activityti1_ on activity0_.id=activityti1_.
detail_id where activity0_.id=?
This is specified in the many-to-one mapping for activityTicket. Saving these two objects works fine.
How do I get hibernate to user detail_id instead of id when loading these two objects?
Regards,
Joshua