-->
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.  [ 7 posts ] 
Author Message
 Post subject: bag with sql-delete
PostPosted: Sun Sep 14, 2008 6:11 pm 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
Hi all

I have a simple map with collection in form:
Code:
.
.
<bag name="biblFiles" table="BIBL_FILES" inverse="false" cascade="all-delete-orphan" lazy="false" >
    <key column="id_object"  not-null="true" update="false" />
    <one-to-many class="com.indexbg.sp.library.db.BiblFiles"/>
     
</bag>
.
.


every time when deleting parent object , children objects deleted 1 by 1.
So i decided to optimize this end trying

Code:
.
.
<bag name="biblFiles" table="BIBL_FILES" inverse="false" cascade="all-delete-orphan" lazy="false" >
    <key column="id_object"  not-null="true" update="false" />
    <one-to-many class="com.indexbg.sp.library.db.BiblFiles"/>
  [b]<sql-delete>DELETE FROM bibl_files where id_object=?</sql-delete> [/b]
</bag>
.
.

but this DELETE statement is never executed.
Where my mistake?

Sorry for my poor English.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Sep 14, 2008 7:55 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Try your first mapping, with cascade set to "save-update" instead of "all".

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 4:28 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
if cascade=save-update" then hibernate first is trying to delete parrent object, and i will have exception - integrity constraint


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 5:20 am 
Proxool Developer
Proxool Developer

Joined: Tue Aug 26, 2003 10:42 am
Posts: 373
Location: Belgium
the correct syntax seems to be:

Code:
all,delete-orphan

_________________
If you found my post helpful, please rate it! Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 5:53 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
nno. this is not decision.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 15, 2008 10:01 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
I just answered a similar post, on how to reduce the number of queries on a cascade delete.

http://forum.hibernate.org/viewtopic.ph ... 70#2395370

Basically, you cannot do it unless the database itself also implements CASCADE DELETE.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 16, 2008 3:45 am 
Beginner
Beginner

Joined: Fri Feb 10, 2006 8:33 am
Posts: 32
Yes, i know this. but this is not my question.
Who will explain how to work with <sql-delete> , <sql-delete-all>?
Can't find working example.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.