-->
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.  [ 2 posts ] 
Author Message
 Post subject: delete with joined-subclass does ignore <key on-delete...
PostPosted: Thu Jan 17, 2008 9:35 am 
Newbie

Joined: Wed Apr 11, 2007 4:04 am
Posts: 2
We have a class Hit with several subclasses (let's say TrademarkHit)

Code:
<class name="com....Hit" table="HIT" abstract="true" >
...
</class>

<joined-subclass name="com....TrademarkHit" table="TRM_HIT" extends="com...Hit" abstract="true">
  <key column="TRM_HIT_ID" on-delete="cascade"/> <!--NOTE THE ON-DELETE !!! -->
</joined-subclass>



It seems that the on-delete="cascade" does have no effect on the executed queries.

Hibernate still first deletes the 'subclass tables', before deleting the 'main class' table: HIT
Code:
DEBUG SQL:401 - delete from CCL_HIT where (CCL_HIT_ID) IN (select HIT_ID from HT_HIT)
DEBUG SQL:401 - delete from NONTRADEMARK_HIT where (NONTRADEMARKHIT_ID) IN (select HIT_ID from HT_HIT)
DEBUG SQL:401 - delete from TRM_HIT where (TRM_HIT_ID) IN (select HIT_ID from HT_HIT)
DEBUG SQL:401 - delete from HIT where (HIT_ID) IN (select HIT_ID from HT_HIT)
DEBUG SQL:401 - delete from HT_HIT 14:09:11,405 
(other tables come from other joined-subclasses)

I would think that Hibernate knows that on-delete cascade is on, so it does not need to delete all subclass tables; this is done by the db (Oracle)

The creation of the temporary table is in this case also not needed.

Any thoughts on this?


Top
 Profile  
 
 Post subject: Re:
PostPosted: Sun Feb 17, 2008 7:54 pm 
Newbie

Joined: Sun Feb 17, 2008 7:21 pm
Posts: 1
hi,

I have the same problem. In my test model, I have a root class Payment and a sub-class CreditPayment. I tried to delete all Payment entities:

String hql = "delete events.Payment";
Query query = session.createQuery(hql);
int req = query.executeUpdate();

The generated statements are as follows:

Hibernate:
insert
into
HT_payment
select
payment0_.payment_ID as payment_ID
from
payment payment0_
Hibernate:
delete
from
credit_payment
where
(
payment_ID
) IN (
select
payment_ID
from
HT_payment
)
Hibernate:
delete
from
payment
where
(
payment_ID
) IN (
select
payment_ID
from
HT_payment
)

And I don't know why there is a temporary table HT_payment used and what the two delete statements are good for. In the mapping I used "on-delete=cascade" already, but it doesn't work.

Your help is greatly appreciated. Thank you, Mia


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.