-->
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.  [ 6 posts ] 
Author Message
 Post subject: Batch deletion
PostPosted: Fri Jul 02, 2004 12:51 am 
Beginner
Beginner

Joined: Mon May 17, 2004 7:15 am
Posts: 24
Is there another way to excecute batch delettion such as a HSQL like:
delelet pack.AnEntity where pack.AnEntity.aProperty > 0 ?

The method delete(String query) provided by the session implementation seems not to do the deletion effetively. First, it finds all entities according to the query and then deletes them one by one. Secondly, the find(String query) will load all propertis of each entity.

Does anybody have expirence in effitive batch deletion, as well as excecuting a HSQL like update or delete?

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 2:00 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Not currently possible. Eventually the bulk update functionality *may* be added.

Quote:
First, it finds all entities according to the query

Of course. It needs to know how to execute cascades.

Quote:
and then deletes them one by one

Yes, this could be optimized.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 5:14 am 
Beginner
Beginner

Joined: Wed Jan 21, 2004 10:15 am
Posts: 24
Location: Munich, Germany
steve wrote:
Quote:
First, it finds all entities according to the query

Of course. It needs to know how to execute cascades.


I always wondered if this is really true. AFAIK, this also happens when there are no cascades defined, and this should be known in advance. I agree that in the case of cascades, every element has to be fetched before it can be deleted, but is it also necessary when there are no cascades defined?

Just an idea, maybe I'm wrong...

Greetings,
Christian


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 12:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Cascading is just one (major) example of why.

In some of my apps using Hibernate, I have implemented auditing systems using Hibernate Interceptors. Without those entities getting loaded first, those apps would have no way to catch notifications that entities were just deleted.

Or what if the application itself is implementing cascade semantics through Interceptorsand/or Lifecycle callbacks? How could that work if we did not load the entities first and fire the various delete notifications?

You have to keep in mind that Hibernate is an Object Relational Mapping tool. Notice "Object" comes first and that I bolded it. Theres a reason for that. The object model is what is important here.

Now, as I mentioned, I think this can be improved such that the delete does not necessarily need to execute deletes one-by-one in these cases (queries and cascdes). But that does not mean that we should get around the loading of entities to delete them.

That being said, Hibernate 3 completely opens this up with its event-driven architecture. It basically says "OK, here's a request do whatever the hell you want even if we do not think its kosher as a core feature". There you would be free to implement loadless deletes if you so want.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 02, 2004 10:49 pm 
Beginner
Beginner

Joined: Mon May 17, 2004 7:15 am
Posts: 24
Many thanks to you all.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 03, 2004 12:09 am 
Beginner
Beginner

Joined: Mon May 17, 2004 7:15 am
Posts: 24
A question similar to gruberc's: Is it necessary to check the nullability of a property (a primary type) when deleting a transient object with its identitfier?

Cheers

James


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