Hibernate version: 2.1.4
Mapping documents:
Code:
<hibernate-mapping>
<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"
cascade=
/>
</class>
<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>
<subclass name="employeeclub.domain.Ticket" extends="employeeclub.domain.Item"/>
<subclass name="employeeclub.domain.ActivityTicket" extends="employeeclub.domain.Ticket" discriminator-value="ACTIVITY_TICKET">
<!-- bi-directional one-to-one association to Activity -->
<one-to-one
name="activity"
class="employeeclub.domain.Activity"
constrained="true"
foreign-key="detail_id"
/>
</subclass>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): N/A
Full stack trace of any exception that occurs:
N/A
Name and version of the database you are using:
MS SQL 2K
Debug level Hibernate log excerpt:
N/A
The Question:
I have the following tables:
Activity
----------------------------------
id
name
description
Item
----------------------------------
id
name
type_id (discriminator, value either "ACTIVITY_TICKET" or "EVENT_TICKET"
detail_id (this is a multi-use foreign key. It links to either Activity or Event based upon the above discriminator)
list_price
unit_cost
description
quantity
The Item table is used to store either ActivityTicket or EventTicket objects. I differentiate between the two objects by using the "type_id" column. The "detail_id" column is used to store the foreign key to either the Activity or Event table.
Currently, I am trying to store an Activity which has a ActivityTicket member variable with the above mapping. The Activity is saving fine. The ActivityTicket is not getting store at all though. What am I doing wrong here?
Regards,
Joshua