-->
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.  [ 2 posts ] 
Author Message
 Post subject: Dependent Object not being saved
PostPosted: Thu Sep 09, 2004 1:37 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"
            outer-join="auto"
            property-ref="activity"
        />
   
    </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>



Code between sessionFactory.openSession() and session.close(): N/A Using Spring

Full stack trace of any exception that occurs: N/A No exception occurs.

Name and version of the database you are using: MSSQL 2k

Debug level Hibernate log excerpt:


All,

I am trying to save an "Activity" object which has a member variable "activityTicket". "Activity" is being saved, but "ActivityTicket" is not. What am I missing here?

Joshua


Top
 Profile  
 
 Post subject: Made change, receiving different error
PostPosted: Thu Sep 09, 2004 2:15 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
All, I changed the Activity mapping to this:

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

</class>


Notice the 'cascade="all"! My mistake. Now that it is trying to save the dependent object though, the DB generates the following error message:

Cannot insert the value NULL into column 'detail_id'

This mapping was declared in the "ActivityTicket" mapping. What gives?

Joshua


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

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.