-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Implementing a one-to-one mapping with Inheritance
PostPosted: Wed Sep 08, 2004 1:23 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.