-->
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.  [ 3 posts ] 
Author Message
 Post subject: many-to-many problem with same table
PostPosted: Fri Aug 04, 2006 10:05 am 
Newbie

Joined: Fri Aug 04, 2006 9:46 am
Posts: 3
Hello,

I've got a problem with a many-to-many relation on the same table.
There is an operation-class which consists of predecessor and successor (both are operations as well)

There are no problems in reading from the database, but when I want to add a new operation only the operation is saved and not the relations in table "presuc", which contains the ids. I know that in "ordinary" many-to-many cases you have to use the property : inverse=true. I've already tried this but the problem was the same.

I'm using hibernate 3.

this is my code from the mapping file:

Code:

<class name="portlet.model.Operation" table="OPERATION">
        <id name="id" column="IDOP">
            <generator class="native"/>
        </id>
        <property name="name"/>
       
        <set name="predecessor" table="PRESUC" lazy="false"  cascade="all">
        <key column="IDSuc" not-null="true"/>
        <many-to-many column="IDPre" class="portlet.model.Operation"/>
        </set>
         
         <set name="successor" table="PRESUC" lazy="false" cascade="all">
        <key column="IDPre" not-null="true"/>
        <many-to-many column="IDSuc" class="portlet.model.Operation"/>
        </set>
</class>


Does anyone have an idea?


Top
 Profile  
 
 Post subject: solved
PostPosted: Wed Aug 09, 2006 5:36 am 
Newbie

Joined: Fri Aug 04, 2006 9:46 am
Posts: 3
I don't know why it didn't work, but it's really the same like with different tables.

Here is my code and know it works ;-)

Code:

<set name="predecessor" table="PRESUC" >
        <key column="IDSuc" not-null="true"/>
        <many-to-many column="IDPre" class="portlet.model.Operation"/>
</set>
         
<set name="successor" table="PRESUC" inverse="true" cascade="save-update">
        <key column="IDPre" not-null="true"/>
        <many-to-many column="IDSuc" class="portlet.model.Operation"/>
</set>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 09, 2006 5:48 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

when using bidirectional associations I think you have to have one end that is responsible for maintaining the corresponding foreign keys (that's IDSuc and IDPre).

Your first code-sample doesn't define inverse=true, so both ends of the association would have to take care of the foreign keys, but that doesn't work (don't ask me for the reason...).

If you specify inverse=true on both ends none of them has to take care of the foeign keys, so nothing will happen on the DB - maybe that's what you tried first.

Your working sample specifies inverse=true on "successor" only, so this end won't update the foreign keys, but the "predecessor"-end will update IDSuc and IDPre in the respective DB-entries.

...at least that's how I understand all this inverse=true stuff....

Greets

piet


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.