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
|