I have a parent object and it has childs.In my database I have one record belong that parent and 3 child record associated with that parent.When I attempt to update childs , that doesn't.And I realized these records is added to table.
MY Parent hbm
Code:
<hibernate-mapping>
<class name="parent" table="Parent">
<id name="id" type="java.lang.Long">
<column name="ID" precision="16" scale="0" />
<generator class="sequence">
<param name="sequence">SEQ_Parent</param>
</generator>
</id>
<property name="cycleCode" type="string">
<column name="CYCLE_CODE" length="10" />
</property>
<set name="cycles" inverse="true" lazy="false" cascade="all" table="CHILD">
<key column="CYCLE_CODE" property-ref="cycleCode" />
<one-to-many class="Child"/>
</set>
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="child" table="CHILD">
<id name="id" type="java.lang.Long">
<column name="ID" precision="16" scale="0" />
<generator class="sequence">
<param name="sequence">SEQ_CHILD</param>
</generator>
</id>
<many-to-one name="cycle" class="parent" column="CYCLE_CODE" property-ref="cycleCode" />
</class>
</hibernate-mapping>
parent p=session.load(1,parent.class);
p.setCycles(Arrays.asList(3,4,5,6);
session.saveorupdate(p);
if my parent has 1,2 as child befor update, after 3,4,5,6 values appears with then in database, I want them to be dropped