-->
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: Populating join table of many-to-many relation doesn't work
PostPosted: Thu Aug 31, 2006 8:06 am 
Beginner
Beginner

Joined: Thu Aug 31, 2006 7:41 am
Posts: 24
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


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.