-->
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: Just modifying junction table
PostPosted: Fri Jun 22, 2007 11:45 am 
Newbie

Joined: Mon Jun 18, 2007 6:33 am
Posts: 3
I have two tables as follows:


Code:
    <class name="com.patix.pojo.Animal" table="Animal" catalog="patix">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity"></generator>
        </id>
        <set name="animalAttributes" inverse="true" cascade="all" table="AnimalAttribute">
            <key>
                <column name="animalId" not-null="true" unique="true" />
            </key>
            <many-to-many column="attributeId" class="com.patix.pojo.Attribute" />
        </set>
    </class>
        <class name="com.patix.pojo.Attribute" table="Attribute" catalog="patix">
        <id name="id" type="java.lang.Integer">
            <column name="id" />
            <generator class="identity"></generator>
        </id>
        <set name="animalAttributes" inverse="true" cascade="all" table="AnimalAttribute">
            <key>
                <column name="attributeId" not-null="true" unique="true" />
            </key>
            <many-to-many column="animalId" class="com.patix.pojo.Animal" />
        </set>
    </class>


I have a form and I am displaying the items in the Attributes table to the user, so he can select the ones he wants. then I would like to add a new animal with the attributes the user has chosen.

What I do is, I create a new animal object and add the attributes to the animalAttributes set of the object, and save. Hibernate inserts the new animal to the animals table, but it doesnt update the junction table AnimalAttribute. from the logs I see "object already associated with session: [com.patix.pojo.Attribute]" so I am guessing that hibernate is not updating the junction table, because I'm not adding a new attribute, but I am just trying to create a new relation.

What do I need to do to make hibernate update the junction table by adding the relations between the new animal and attributes that already exist.

Thanks


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.