I have written some DAO methods that do bulk updates / deletes with HQL but I see that when the query is executed the entities in memory are not sychronized (the cache is not updated).
Say, I have a collection of Projects with a collection of Groups each and I want to delete all Groups. I can iterate the Groups and delete each but I prefer to run a bulk delete with HQL and IN operator. However, the list has the old objects after the query is executed.
I realized that I have to refresh the objects with session.refresh(). Is there any other way I can bulk update and update cache automatically?
The answer is NO. As documented here:
13.3. DML-style operations
cite:
DML is there for us, to skip the state management in memory...being more efficient from SQL statements point of view. But that means: