-->
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: Hibernate cascade mapping help (unecessary sql generated)
PostPosted: Fri Jul 28, 2006 2:18 pm 
Newbie

Joined: Thu May 18, 2006 1:46 pm
Posts: 10
Hello there, I'm using hibernate 3.1.2, and I have a one-to-many association using a set. My cascade is set to save-update. When I add a new element to my collection and update it, it's generating a insert for the new element (expected) and updating every element of the collection, plus updating the other entities:

It inserts a new vote, updates all votes in the collections and updates voter and building. I was expecting only insert to happen

Here's my mapping:

Code:
<hibernate-mapping
>
    <class
        name="Voter"
        table="VOTER"
    >

        <id
            name="id"
            column="ID"
            type="java.lang.Long"
        >
            <generator class="sequence">
                <param name="sequence">SEQ_VOT</param>
           
            </generator>
        </id>
    <set
            name="votes"
            lazy="false"
            inverse="true"
            cascade="save-update"
            sort="unsorted"
        >

            <key
                column="ID_VOTER"
            >
            </key>

            <one-to-many
                  class="Vote"
            />

        </set>
</hibernate-mapping>

<hibernate-mapping
>
    <class
        name="Vote"
        table="VOTE"
    >

        <id
            name="id"
            column="ID"
            type="long"
        >
            <generator class="sequence">
                <param name="sequence">SEQ_VOTE</param>
           
            </generator>
        </id>

        <many-to-one
            name="building"
            class="Building"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="ID_BUILD"
        />

        <many-to-one
            name="voter"
            class="Voter"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="ID_VOTER"
        />
    </class>

</hibernate-mapping>


It's a simple voting mechanism, where for each vote we track the voter and the building he voted for.

Any ideas?

Regards


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.