aspose file tools*
The moose likes Object Relational Mapping and the fly likes HIBERNATE - Dependent objects FK not getting set Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "HIBERNATE - Dependent objects FK not getting set" Watch "HIBERNATE - Dependent objects FK not getting set" New topic
Author

HIBERNATE - Dependent objects FK not getting set

Joshua White
Ranch Hand

Joined: Jun 04, 2001
Posts: 97
All,

When attempting to save an object with a dependent object, my dependent objects FK is not getting set. Here are the mapping files:

<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"
outer-join="auto"
property-ref="activity"
cascade="all"
/>
</class>

<subclass name="employeeclub.domain.ActivityTicket" extends="employeeclub.domain.Ticket" 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>
</hibernate-mapping>

When attempting to save an "Activity" object (with "ActivityTicket" member variable), SQL Server complains that I cannot insert a row into the Item table (where ActivityTicket's are being inserted) because "detail_id" is null.

What am I missing here?

Regards,

Joshua
 
Don't get me started about those stupid light bulbs.
 
subject: HIBERNATE - Dependent objects FK not getting set