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
|