-->
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.  [ 3 posts ] 
Author Message
 Post subject: Bulk delete - conceptual question
PostPosted: Wed Oct 17, 2007 9:07 pm 
Newbie

Joined: Wed Oct 17, 2007 8:56 pm
Posts: 2
Would like to understand at a high level how the bulk delete in Hibernate (assume latest version of the code) is implemented. I just want to make sure we're using Hibernate the way it is intended. I don't believe this is spelled out in the doc as clearly as I would like, but apologies in advance if it is and I somehow missed it.

Suppose I start a transaction, query a few instances of persistent class C (so that some are in the cache) and then do a bulk delete via HQL (e.g., "delete from C").

Questions:

1) Are all instances - those in the cache or not in the cache - deleted? I assume so, but I have seen other forum messages and some info in Chapter 13 that makes me wonder whether this is indeed the case. Also, the EJB-QL spec makes special note of this as well:

Caution should be used when executing bulk update or delete operations because they may result in inconsistencies between the database and the entities in the active persistence context. In general, bulk update and delete operations should only be performed within a separate transaction or at the beginning of a transaction (before entities have been accessed whose state might be affected by such operations).

2) If I were to use a "delete..where" syntax, is it possible to get a simple explanation of how this works, again at a high level? e.g., does Hibernate query all instances in the cache, delete them in bulk via their keys, and then delete in bulk all non-cached instances.

I apologize if I'm using the term "instance" incorrectly here. We want to make good use of Hibernate at our company and I want to understand things from a correctness perspective before we embark on using such features.

Thank you.

-K


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 1:49 am 
Regular
Regular

Joined: Wed Jun 20, 2007 1:53 am
Posts: 75
Hi,
HQL won't support for update or delete operation directly. If you want to delete or update the record using Hibernate then use saveOrUpdate() or delete() in session object and this will support single entity(or row) deletion or updation.

If you want to execute batch update the go for sql in Hibernate that means use executeSQL(...). If we use sql then catch not come into picture.

In general bulk update or delete operations are not suggessted.

- Shanmugam.N


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 18, 2007 2:22 am 
Newbie

Joined: Wed Oct 17, 2007 8:56 pm
Posts: 2
Thanks for the try, but bulk delete and update are first class features of Hibernate 3, so I am sure they are both supported and suggested.

I have read several forum messages from folks on this topic and the development team, as best I can tell, has never steered people away from using them, so I don't see any need to be afraid of using them. Most of the discussion has been to clarify things like cascades, etc.

My question is focused on the correctness with regards to caching. I know the session cache is not updated during bulk deletes, but I would like to confirm that the 2nd level cache is, especially when DELETE..WHERE is issued and also that support is not limited to those entities with only certain types of associations, etc.

Again, thanks for the try...


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