-->
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: many-to-many mapping with join tables
PostPosted: Sat Aug 02, 2008 8:25 am 
Newbie

Joined: Sat Aug 02, 2008 7:53 am
Posts: 9
Location: Mumbai, India
hi all,

i started hibernate some days b4. and trying to do many to many with join table mapping for two table.
I want to tell you 1stly the specifiaction i'm using
version : Hibernate 3.0
framework : spring2.0
data base : MySQL

now here is what i'm doing.

Table1 :-> Class Name - com.infotech.Table1.
This Parent Table
Column - > 1. id - Primary Key, bigint(20), Not Null, Auto Increment
2. Name
3. Level


Table2 :-> Class Name - com.infotech.Table2
This is child table
Column - > 1. id - Primary Key, bigint(20), Not Null, Auto Increment
2. Name
3. Level

Table3 :-> this is joining table
Column - > 1. table1_id - Primary Key, bigint(20), Not Null
2. table2_id - Primary Key, bigint(20), Not Null


Table1.hbm.xml
--------------------
<hibernate-mapping>
<class name="com.infotech.Table1" table="Table1" lazy="false">
<id name="id" column="id" unsaved-value="null">
<generator class="identity">
</generator>
</id>
<property name="name" column="Name"/>
<property name="level" column="Level"/>
<set name="table2" table="Table3" lazy="false" cascade="save-update">
<key column="table1_id" />
<many-to-many class="com.infotech.Table2" column="table2_id" outer-join="auto"/>
</set>
</class>
</hibernate-mapping>


Table2.hbm.xml
------------------
<hibernate-mapping>
<class name="com.infotech.Table2" table="Table2" lazy="false">
<id name="id" column="id" unsaved-value="null">
<generator class="identity">
</generator>
</id>
<property name="name" column="Name"/>
<property name="level" column="Level"/>
</class>
</hibernate-mapping>

Now The Problem arrises.

when i try to save an object of Table1 which is having a well populated SET of Table2 with 2 values (means SET of Table2 is having two object of Table2), the values are getting stored in Table1 but the mapping Table i.e Table3 is not getting populated.

Its a unidirectional association with join table.

_________________
Sushant


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.