I have 2 tables, table A (parent) & table B(child) , table A to table B is One-To-Many relationships
here is my mappings
<class name="ObjectA" table="Table A"> <id name="id" column="id"> <generator class="sequence"> <param name="sequence">parent_id_s</param> </generator> </id> <property name="userId" column="user_id"></property> <property name="name" column="name"></property> <set name="ObjectB" cascade="all"> <key column="id"></key> <one-to-many class="Object B"/> </set> </class>
<class name="Object B" table="Table B"> <id name="addressId" column="address_id"> <generator class="sequence"> <param name="sequence">child_id_s</param> </generator> </id> <property name="id" column="id"></property> <property name="address" column="address"></property> </class>
so id column of Table A is PK and id column of Table B is the FK of the same. As i said its 1 to Many relationships, One User(Object A/TableA) will have more than one Address Information(Object B/Table B), I tried to insert a new User record with One Address , It created a record in Table A and one record in Table B, Now i am trying to update User Info with another Address, in this Scenario it got updated the Table A and created another record in Table B which is fine, But its removing the value of the id field(FK) of the Previous Address Record. is there anything wrong with the Mapping above ?
any help would be much appreciated.
regards DP
|