Hi,
I have a problem with hibernate3 and a many-to-many association. The two mapping snippets look like this:
Code:
<hibernate-mapping>
<class name="de.zgdv.rostock.ceismedia.hibernate.Media" table="media" catalog="ceismedia">
<comment></comment>
<id name="id" type="int">
<column name="id" />
<generator class="native" />
</id>
<set name="keywords" table="media2keyword" cascade="persist,merge,save-update" lazy="true">
<key column="Media_id" not-null="true"/>
<many-to-many column="Keyword_id" class="de.zgdv.rostock.ceismedia.hibernate.Keyword" />
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="de.zgdv.rostock.ceismedia.hibernate.Keyword" table="keyword" catalog="ceismedia">
<comment></comment>
<id name="id" type="int">
<column name="id" />
<generator class="native" />
</id>
<set name="medias" table="media2keyword" inverse="true" lazy="true">
<key column="Keyword_id" not-null="true" />
<many-to-many column="Media_id" class="de.zgdv.rostock.ceismedia.hibernate.Media" />
</set>
</class>
</hibernate-mapping>
I save this by doing
Code:
Media mi = new Media();
Keyword k = new Keyword();
k.setLabel("Foo");
k.getMedias().add(mi);
mi.getKeywords().add(k);
session.saveOrUpdate(mi);
But the join table stays empty, the other two are populated though. I tried various things but nothing helped. Anybody with a tip on how to resolve this?
Andreas