-->
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: Cascade delete.
PostPosted: Sat Oct 21, 2006 10:46 pm 
Newbie

Joined: Sat Oct 21, 2006 10:34 pm
Posts: 1
I am having an issue with cascade delete operation. I am doing pretty complex delete operation - deleting PropertyInfo object which is related oneToOne to Property object, which has list of Ad objects, which have set of Image object in them. Everything works just fine. But I am noticing redundant select and update operations which is bugging me.

Here is how tipical delete statements look:

Hibernate: select propertyin0_.pi_id as pi1_3_4_, propertyin0_.count_ads as count2_3_4_, propertyin0_.last_ad_id as last7_3_4_, propertyin0_.max_price as max3_3_4_, propertyin0_.min_price as min4_3_4_, propertyin0_.start_date as start5_3_4_, propertyin0_.end_date as end6_3_4_, ad1_.id as id0_0_, ad1_.property_id as property8_0_0_, ad1_.post_date as post2_0_0_, ad1_.link as link0_0_, ad1_.title as title0_0_, ad1_.description as descript5_0_0_, ad1_.cache_id as cache6_0_0_, ad1_.price as price0_0_, property2_.id as id2_1_, property2_.address_id as address8_2_1_, property2_.type as type2_1_, property2_.bed as bed2_1_, property2_.bath as bath2_1_, property2_.relevance as relevance2_1_, property2_.square as square2_1_, property2_.story as story2_1_, property3_.id as id2_2_, property3_.address_id as address8_2_2_, property3_.type as type2_2_, property3_.bed as bed2_2_, property3_.bath as bath2_2_, property3_.relevance as relevance2_2_, property3_.square as square2_2_, property3_.story as story2_2_, address4_.id as id1_3_, address4_.longitude as longitude1_3_, address4_.address as address1_3_, address4_.state as state1_3_, address4_.country as country1_3_, address4_.city as city1_3_, address4_.zip as zip1_3_, address4_.resolved as resolved1_3_, address4_.latitude as latitude1_3_ from property_info propertyin0_ left outer join ad ad1_ on propertyin0_.last_ad_id=ad1_.id left outer join property property2_ on ad1_.property_id=property2_.id left outer join property property3_ on propertyin0_.pi_id=property3_.id left outer join address address4_ on property3_.address_id=address4_.id where propertyin0_.pi_id=?
Hibernate: select ads0_.property_id as property8_1_, ads0_.id as id1_, ads0_.id as id0_0_, ads0_.property_id as property8_0_0_, ads0_.post_date as post2_0_0_, ads0_.link as link0_0_, ads0_.title as title0_0_, ads0_.description as descript5_0_0_, ads0_.cache_id as cache6_0_0_, ads0_.price as price0_0_ from ad ads0_ where ads0_.property_id=? order by ads0_.post_date asc

I'm totally fine until this moment, here it selects all my images which are going to be removed in a moment, when clears association field, and then removes them one by one.

Hibernate: select images0_.ad_id as ad8_1_, images0_.id as id1_, images0_.id as id4_0_, images0_.name as name4_0_, images0_.type as type4_0_, images0_.data as data4_0_, images0_.height as height4_0_, images0_.width as width4_0_, images0_.mime as mime4_0_ from image images0_ where images0_.ad_id=?
Hibernate: select images0_.ad_id as ad8_1_, images0_.id as id1_, images0_.id as id4_0_, images0_.name as name4_0_, images0_.type as type4_0_, images0_.data as data4_0_, images0_.height as height4_0_, images0_.width as width4_0_, images0_.mime as mime4_0_ from image images0_ where images0_.ad_id=?
Hibernate: update property_info set count_ads=?, last_ad_id=?, max_price=?, min_price=?, start_date=?, end_date=? where pi_id=?
Hibernate: update image set ad_id=null where ad_id=?
Hibernate: update image set ad_id=null where ad_id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from ad where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?
Hibernate: delete from image where id=?

Here normal remove block goes.

Hibernate: delete from ad where id=?
Hibernate: delete from property where id=?
Hibernate: delete from property_info where pi_id=?

Is there way to work around or fix redundant statements so it calls:
DELETE FROM image WHERE ad_id = ?

Thanks.


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.