-->
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.  [ 4 posts ] 
Author Message
 Post subject: how to delete this entity along with its associations?
PostPosted: Fri Feb 10, 2006 11:33 am 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
the problem here is I defined the hbm mapping file by myself:
I first generated a hbm file using middlegen,then I manually
deleted the association definitions as below,for the BO here
need not to be aware of the loading of these sets,I delete
these definitions for the sake of simpleness of this BO.

<set
name="clips"
lazy="true"
inverse="true"
cascade="all"
>
<key>
<column name="article_id" />
</key>
<one-to-many
class="com.libInformation.bo.Clip"
/>
</set>
....

here comes the question,the set definitions are gone,there's
nowhere to define the cascade property;then when deleting this
BO it turns out that "a foreign key constraint fails"

how to handle this situation?can I keep my hbm-file unchanged
and simultaneously handle the deleting problem?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 2:38 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
hibernate3 has adapted the EJB3 spec following delete criteria. Unless you're in the same session as an object was loaded (or that you've persisted with that session), it will not cascade the deletes automatically. This is to improve performance becuase H used to load everything into memory then delete everything... which is alot of extra work.

I recommend writing custom delete sql/hql statements which have much better performance...

another less performant way is to just call delete on every object in a set, then null out the set, then delete the parent

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 9:14 pm 
Newbie

Joined: Fri Oct 28, 2005 10:32 pm
Posts: 13
thank you for replay:)
kochcp wrote:
hibernate3 has adapted the EJB3 spec following delete criteria.

what's EJB3's delete criteria?


kochcp wrote:
I recommend writing custom delete sql/hql statements which have much better performance...

another less performant way is to just call delete on every object in a set, then null out the set, then delete the parent

in this way need I change the database DDL to change the reference to
be "ON DELETE CASCADE"?or I don't know how to write a single hql to
do the job..


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 11:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
I think kochcp may be confusing the HQL DELETE statement. It sounds like you are just trying to do : session.delete( someEntity ), right?

Hibernate can only cascade operations to stuff it knows about, and it only knows about stuff you have told it about in the metadata. Since you have removed that association from the metadata (the mapping file) Hibernate has no way to know that it should be doing a cascade to those rows.

So your two options are (1) anually delete all related Clip rows; (2) use of DB-level cascading constraints.

Not that #2 causes problems here also since there is a potential for rows to be get deleted where Hibernate knows nothing about those deletes.


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