-->
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: Cascade update executes an insert
PostPosted: Fri Feb 19, 2010 5:07 pm 
Newbie

Joined: Fri Feb 19, 2010 4:53 pm
Posts: 1
I am using Hibernate 3.2. I have a two tables Test, Query and QueryPart with a one-to-one mapping between Test and Query as below and one-to-many mapping between Query and QueryPart as below. However, when I try to do an update on Test, there is a new entry inserted into the Query and QueryParts table, instead of doing an update. Why would that be and how would I fix that?

Code:
<hibernate-mapping>

    <class name="com.test.Test"
           mutable="false"
           table="TEST">

        <cache usage="nonstrict-read-write"/>

        <id name="id" column="shared_id" access="field">
            <generator class="native"/>
        </id>

   <many-to-one name="testQuery" access="property" column="query_id"
            foreign-key="query_id_fk"
            cascade="save-update,delete" unique="true"
            not-null="true"/>

    </class>

</hibernate-mapping>


Code:
<hibernate-mapping>

    <class name="com.test.Query" table="QUERY">

        <cache usage="nonstrict-read-write"/>

        <id name="id" column="QUERY_ID">
            <generator class="native"/>
        </id>

        <list name="queryParts" table="QUERY_PARTS" cascade="all-delete-orphan" access="field">
            <cache usage="nonstrict-read-write"/>
            <key column="QUERY_ID" foreign-key="QUERY_ID_FK" not-null="true"/>
            <list-index column="QUERY_INDEX"/>
            <one-to-many class="com.company.QueryPart"/>
        </list>

    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject: Re: Cascade update executes an insert
PostPosted: Sat Feb 20, 2010 8:57 pm 
Beginner
Beginner

Joined: Wed Nov 21, 2007 8:02 am
Posts: 48
I can't see what method you are using to update. But you have defined your Test class as immutable.
You have to remove the "mutable='false'"


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.