-->
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.  [ 5 posts ] 
Author Message
 Post subject: many-to-many insert, middle table not inserting
PostPosted: Thu Oct 26, 2006 4:15 pm 
Newbie

Joined: Thu Oct 26, 2006 3:58 pm
Posts: 2
have a many to many relationship that works great for existing data:

Person object can have many Editorships
Editorship can have many Person objects.

middle table is named

Person_xref_Editorships, has 2 columns after the key: Person_id and Editorships_id

Now, whenever updating existing data, all works well. However, when I have a new Editorship, I add it to my Set in java, it gets written to the Editorship table.

the problem is that nothing gets written to Person_xref_Editorships table, thereby effectively losing the association at the data level between the Person and the New Editorship.

typos below are my fault, the hbm.xml files work fine for what they do.

Person .hbm.xml:

<hibernate-mapping>
<class name="cooptor.PersonBean" table="Person" >
<id column="id" type="int" >
<generator class="select"/>
</id>

<property name="id" insert="false" update="false"><column name="id"/></property>
<property name="_dateStart"><column name="_dateStart"/></property>

<set name="editorships" inverse="true" table="Person_xref_Editorship" cascade="save-update" >
<key column="Position_id" not-null="true" />
<many-to-many column="Editorship_id" class="cooptor.EditorshipBean" lazy="false"/>
</set>

</class>
</hibernate-mapping>

and Editorship.hbm.xml:

<hibernate-mapping>
<class name="cooptor.EditorshipBean" table="Editorship3" >
<id column="id" type="int" >
<generator class="select"/>
</id>

<property name="id" insert="false" update="false"><column name="id"/></property>
<property name="_editorshipSociety"><column name="_editorshipSociety"/></property>

<set name="people" table="Person_xref_Editorship" >
<key column="Editorship_id" not-null="true" />
<many-to-many column="Person_id" class="cooptor.PersonBean" lazy="false" />
</set>

</class>
</hibernate-mapping>

the "primary" relationship is from the Person to the editorship, but it can go the other way.

and lastly here's the code to add a new editorship:


public String addNewEditorship ()
{
editorships.add(new EditorshipBean());
return "gotoUnit";
}


or maybe this is a java problem and not a hibernate problem?

i'm stumped, thanks for any help you can provide


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 26, 2006 11:57 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
I assume that the method you provide is on a Person. You set the inverse=true attribute in the hibernate mapping which means that Person does NOT manage the relationship. A first step is to set inverse=false.

I hope this helps :)

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 8:54 am 
Newbie

Joined: Thu Oct 26, 2006 3:58 pm
Posts: 2
Ok, thanks for the tip.

I changed it, and the problem remains unchanged....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 01, 2006 1:49 pm 
Newbie

Joined: Tue Oct 31, 2006 2:34 pm
Posts: 7
stucky,
i'm having the exact same problem.
Have you found a solution yet?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 02, 2006 1:42 pm 
Newbie

Joined: Tue Oct 31, 2006 2:34 pm
Posts: 7
stucky
i solved my issue with this problem

i had to put a Flush() in just after my save.

If it is not wrapped in a transaction its queue's the input to the join table.


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