| I have two tables, quotation and quotation_items. There is one to many relationship them. My requirement is when I do quotation.setQuotationItems(set), old quotationItem mapped to quotation should get removed and quotationItems in set should get mapped against quotation.
 My Quotation pojo is like
 public class Quotation {
 int quotationId;
 String code;
 String clientName;
 Set<QuotationItems> quotationItem=new HashSet<QuotationItems>();
 //getter and setter
 }
 
 QuotationItems POJO
 public class QuotationItem extends Quotation{
 int id;
 Quotation quotation;
 String itemName;
 int rate;
 int qty;
 //getter and setter
 }
 
 Quotation.hbm
 <hibernate-mapping>
 <class name="com.paramatrix.pojo.Quotation" table="quotation" >
 <id name="quotationId" type="int" column="quotation_id">
 <generator class="native" />
 </id>
 <property name="code" column="code" type="string" />
 <property name="clientName" column="client_name" type="string" />
 <set name="quotationItem" table="quotation_item" cascade="all-delete-orphan" inverse="true">
 <key>
 <column name="quotation_id" not-null="true" />
 </key>
 <one-to-many class="com.paramatrix.pojo.QuotationItems" />
 </set>
 </class>
 </hibernate-mapping>
 QuotationItem.hbm
 <class name="com.paramatrix.pojo.QuotationItems" table="quotation_item" dynamic-insert="true">
 <id name="id" type="int" column="id">
 <generator class="native" />
 </id>
 <many-to-one name="quotation" class="com.paramatrix.pojo.Quotation" >
 <column name="quotation_id" not-null="true" />
 </many-to-one>
 <property name="itemName" column="item_name" type="string" />
 <property name="rate" column="rate" type="int" />
 <property name="qty" column="qty" type="int" />
 </class>
 
 My tables structure is like for Quotation
 
 quotation_id | code | client_name
 
 My table structure for Quotation_items
 
 id | quotation_id | item_name | rate | qty
 
 
 Scenario is If I put 3 quotationItem in a Set<QuotationItem> and then assign that set to Quotation.setQuotationItem(set). Next time when I put 2 different quotationItem in a Set & then assign that set to Quotation then these two new quotationItem are also get mapped with Quotation. BUT I WANT ONLY LAST TWO QUOTATION ITEM GET MAPPED WITH QUOTATION.
 
 To  work around, I made cascade = “all-delete-orphan” of set in quotation and instead of doing
 quotation.setQuotationItems(set),
 I did following......
 quotation.getQuotationItems().clear();
 quotation.getQuotationItems().addAll(newSet);
 
 It worked fine until, in findDirty() or onFulushDirty method of Interceptor I am getting same values of old set and new set of quotationItems. If remove quotation.getQuotationItems().clear(); quotation.getQuotationItems().addAll(newSet);
 
 I get different values for old and new set(as expected) and then “all-delete-orphan” functionality doesn't work.
 
 Any suggestions ?
 
 
 |