-->
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: delete-orphan and tracking history (audit trail)
PostPosted: Thu Jul 17, 2014 7:36 am 
Newbie

Joined: Mon Mar 03, 2014 1:29 pm
Posts: 3
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 ?


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.