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
|